Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does releasing a UIView release all its subviews?

If I have a UIView, and I add an allocated subview into it (in this case the UIImageView), when I release the UIView, will UIImageView also be released?

I set up my view and a subview like this:

UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
UIImage *myImage=[UIImage imageNamed:@"image.png"];

// This is the subview:
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.image=myImage;

[view addSubview:imageView];
[imageView release];

Now, when I call:

[view removeFromSuperview];
[view release];

Will the allocated imageView also be released, or should I remove it by removing all of the view's subviews?

Any insight on this topic is greatly appreciated.

like image 652
pop850 Avatar asked Jul 26 '10 22:07

pop850


1 Answers

Yes. The UIView "owns" the subviews so it releases them when it is itself dealloc'd.

like image 179
Bill Avatar answered Nov 16 '22 12:11

Bill