Good question, I wanted to ask the same thing. I guess there's no way to verify subviews being deallocated, except to watch Instruments app and see if memory use keeps rising..? Isn't there a better way to monitor this?
Anyway, here's my code example..
Code:
@interface MyTile : UIView {
NSInteger theNumber;
}
@property (assign, nonatomic) NSInteger theNumber;
-(id)initWithFrame:(CGRect)frame andNumber:(int)aNumber;
and the code to initialise MyTile view
Code:
-(id)initWithFrame:(CGRect)frame andNumber:(int)aNumber {
[super initWithFrame: frame];
// load the image and resize it
UIImageView *tmpImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tilegraphic.png"]];
tmpImage.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
// add image to view
[self addSubview: tmpImage];
[tmpImage release];
// set number property
self.theNumber = aNumber;
// add label with text
UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
tmpLabel.backgroundColor = [UIColor clearColor];
[tmpLabel setTextAlignment:UITextAlignmentCenter];
tmpLabel.text = @"123";
// add labelview to imageview
[self addSubview:tmpLabel];
[tmpLabel release];
// return pointer to self, for use outside this constructor method
return self;
}
Now, when I'm done with the tiles from one game (each new game can have different tile dimensions etc.) I send a release to all of the MyTiles.
The question is: will the UIImageView ("tilegraphics.png") and the UILabel ("123") views also be released or will they cause a memory leak? If so, do I have to add a UIImageView and UILabel pointer to MyView class, just so I can send them a release-message in the MyTile dealloc?