How to detect if a variable has not been released in Objective-C?
I've removed few release from my code to see if Leaks instrument in xCode can notify me about the bad code:
...
UINavigationController *masterNav = [[UINavigationController alloc] initWithRootViewController:master];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detail];
[master release];
splitViewController.viewControllers = [NSArray arrayWithObjects:masterNav, detailNav, nil];
//[masterNav release]; [detailNav release]; commented out
However I can't see any notification. Is because the memory allocated for such variables is too small ? I need a memory management tool in this phase in which I'm learning object开发者_JAVA技巧ive-C
thanks
Your over-retain (of detailNav) is not a leak yet, because it is still referenced by splitViewController.viewControllers. That's why Instruments won't show it as a leak.
Instruments does not flag over-retains (it can't). Only when your object is orphaned, i.e., after all other non-leaked objects have released their references, will Instruments flag it as a leak.
Have you tried Product->Analyze
in Xcode4? That should show you the leak.
go to xcode and select the project.Then click on the build and anlayze .It will gives you some of the memory leaks
精彩评论