views:

46

answers:

2

Hi, I have a custom view controller that I push onto my navigation stack as follows:

myViewController *myVC = [[myViewController alloc] init];
[myVC generate:myData];
[self.navigationController pushViewController:myVC animated:YES];

the code runs fine, but when checking for memory leaks I get a warning that myVC is never released.

adding a release statement

[myVC release];

in line 4 compiles fine, but crashes in execution. How do I need to handle this?

+1  A: 

My guess is that it has nothing to do with this section of code. The problem is that before, since you weren't releasing it here, it was never deallocated. Now that it is being deallocated when you pop the view controller from the navigation stack, it's calling the dealloc method of myViewController, and some string object is being over-released in there.

Presumably at some point some string variable is set inside your myViewController without retaining it or it is released without being set to null, then later you release it again.

Ed Marty
+1  A: 

Yes, you should release your view controller.

The error message you see results from a memory management problem inside your view controller - it would seem that you over-release a NSString object.

Paul Lynch