views:

1148

answers:

2

Hi developers,

I am currently working on an application which displays several UIViews in a UIScrollView. This UIScroll is inside a UIViewController.

(In a loop I am creating new UIViews with autorelease and add them to the scroll view. Could this be the problem?)

When I try to release the viewController all the subviews with their label, images, etc are staying in the memory.

What would be the best way to get rid of those objects?

Thanks for your help!

Thomas

+1  A: 

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.

Adam Rosenfield
+2  A: 

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.

Andy White