views:

19

answers:

2

Hi all,

My modal view controller is not calling its dealloc method when it dismisses itself. I have presented it using :

ViewController * vl = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];  
self.viewLink = vl;

[mainMenu stop];
[mainMenu setCurrentTime:0.0];

[vl release];

[self presentModalViewController:viewLink animated:NO];

Any ideas ?

Thanks,

Martin

A: 

Assuming viewLink is a @property(retain), it isn't being deallocated because that object is retaining the modal view controller.

Chuck
Thanks. So I should release viewLink when I return from my modal view controller ? What is the best way to do that - should I do [self release] in the modal view controller ?
Ohnomycoco
@Ohnomycoco: You should set `viewLink` to `nil` when you're done with it.
Chuck
Thanks. How can I time time self.viewLink = nil to fire when the modalviewcontroller is dismissed ?
Ohnomycoco
+1  A: 

You may not really need to set viewLink because when you present a modal view controller a reference to it will be stored in self.modalViewController. This will automatically get set to nil once you dismiss the controller and the dismissal animation has finished.

Nimrod
Thanks. I've tried setting to the following an it now crashes viewLink = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]]; [mainMenu stop]; [mainMenu setCurrentTime:0.0]; [viewLink release]; [self presentModalViewController:viewLink animated:NO];
Ohnomycoco
Eeeeh don't you think you should release viewLink AFTER you call presentModalViewController? ;-) Now you release it before it's used!
Meta-Knight