Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using dismissModalViewControllerAnimated won't free any memory

I have a very simple code to show a modal controller (nextController is a class member):

nextController = [[InstructionsScreen alloc] initWithNibName:@"InstructionsScreen" bundle:nil];
[self presentModalViewController:nextController animated:YES];
[nextController release];

And then when the controller should hide:

[self dismissModalViewControllerAnimated:YES];
nextController = nil;

All works good as expected, but when I run instrument Object Allocations it shows that after dismissing the modal controller the memory it allocated is not freed. This becomes a problem because when I show several controllers the memory is over ...

Can anybody give me some clues ? Clang doesn't see any problems, so I'm stuck hitting the memory limit, because the memory of the dismissed controllers won't get released.


EDIT: What I discovered up to now is that it seems to be a leak somewhere in Apple's stuff. Way to reproduce: XCode -> create new project with the template "Utility application". Don't write any code yourself. Just create a new utility application and run it with "Object allocations", choose to see "Created & Still living". Now flip the modal controller few times - you'll see the allocated memory only grows and grows every time the modal controller is appearing and when it's disappearing too ...

like image 738
Marin Todorov Avatar asked Dec 03 '09 21:12

Marin Todorov


1 Answers

There is no leak in the code you show as far as I can see. There could be a leak in InstructionsScreen that would prevent it being deallocated.

I think it's worth running the Static Analyser to see if it finds a leak.

The leak in the Apple template code is interesting. It could be that there is a leak. It seems unlikely but obviously it's not impossible. I would say that it's more likely that it's a false-positive in Instruments, which is why I'd suggest using the Static Analyser.

(You might want to raise a bug report about the leak.)

like image 180
Stephen Darlington Avatar answered Oct 09 '22 01:10

Stephen Darlington