Reputation: 439
I am currently working on an application which displays several UIView
s in a UIScrollView
. This UIScrollView
is inside of a UIViewController
.
In a loop I am creating new UIView
s, autorelease
them and add them to the scroll view. Could this be the problem?
When I try to release the view controller all the subviews with their labels, images, etc are staying in the memory.
What would be the best way to get rid of those objects?
Upvotes: 1
Views: 2224
Reputation: 88345
I think this might be what's going on:
When you add a UIView to a UIScrollView, the UIScrollView will retain it. You are also calling autorelease on the UIView, so the object is now retained by the UIScrollView and the NSAutoreleasePool. When you release the viewController, it will bump the retain count down by one, but the objects will not be deallocated until you get to the drain call for your current NSAutoreleasePool.
Maybe try not autorelease'ing the objects in the loop. Just add them to the UIScrollView, then manually release them. In this way, the UIScrollView will be the sole owner of these objects.
Upvotes: 2
Reputation: 400156
It's impossible to tell without seeing some code. Post a snippet of the code you believe to be suspect. Make sure you're following all of the rules laid out in the Memory Management Programming Guide for Cocoa.
Upvotes: 1