Note that there are some explanatory texts on larger screens.

plurals
  1. POrelease or not release a controller
    text
    copied!<p>First of all, sorry for my english (I'm spanish) and for being a newbie. I am developing my second iPad app for learnign and I am having problems with the memory management. I am facing this problem for about a month now, so I have thought that maybe some expert in this great community could help me a bit. </p> <p>My scenario is: </p> <p>It is a simple e-book app. I have a main view from which the user can open two modal views. The main issue is in one of the modal views. In there I have a scrollview that manages all the pages. Right now, there are 12 pages. I have tried to release everything, etc, but something remains in memory, because in instruments memory keeps growing and when I dissmiss the modal view and come back, after a few times, it crashes. The pages are separate xibs and I load them with this method:</p> <pre><code> - (void)loadScrollViewWithPage:(int)page { if (page &lt; 0) return; if (page &gt;= MyNumberOfPages) return; if ((NSNull *)controller != [NSNull null]) { NSString *className = [NSString stringWithFormat:@"Pagina%d", page]; Class myClass = NSClassFromString(className); controller = [[myClass alloc] initWithNibName:className bundle:nil]; // I have tried autorelease and even retain] autorelease. [viewControllers replaceObjectAtIndex:page withObject:controller]; CGRect frame = scrollView.frame; frame.origin.x = frame.size.width * page; frame.origin.y = 0; controller.view.frame = frame; if (page != 0){ controller.view.tag = page; }else { controller.view.tag = 9999; } [scrollView addSubview:controller.view]; [scrollView sendSubviewToBack:controller.view]; [controller release]; } } </code></pre> <p>I load 3 pages each time, the one visible and left and right ones. I try to unload (remove or get rid of) them this way (for the ones around the 3 loaded):</p> <pre><code>[viewControllers removeObjectAtIndex:pagi - 2]; [[scrollView viewWithTag:pagi - 2] removeFromSuperview]; </code></pre> <p>So I have two problems... If I release the controller as I am doing in the method above, my IBActions in some pages crash the app. But If I release it anyway, and remove IBActions, the memory keeps growing too. In Instruments, it shows no leaks, but it crashes after growing 1mb or 2mb of memory.</p> <p>I have logued all the pages viewDidUnload and deallocs and they unload only when there is a memory warning. </p> <p>Finally, what is more strange for me, is that if I don't use [controller release]; the apps stays more time without crashing. But of course, they don't dealloc.</p> <p>I think that the problem may be in this method, but if it helps, I could upload more parts of the code. It's just to don't make it too long here.</p> <p>Any idea?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload