aneuryzm
aneuryzm

Reputation: 64834

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 objective-C

thanks

Upvotes: 1

Views: 348

Answers (3)

Steven Kramer
Steven Kramer

Reputation: 8513

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.

Upvotes: 1

Tendulkar
Tendulkar

Reputation: 5540

go to xcode and select the project.Then click on the build and anlayze .It will gives you some of the memory leaks

Upvotes: 0

David
David

Reputation: 14404

Have you tried Product->Analyze in Xcode4? That should show you the leak.

Upvotes: 0

Related Questions