Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-20-2010, 01:42 PM   #1 (permalink)
NJ1
Registered Member
 
Join Date: Dec 2010
Posts: 4
NJ1 is on a distinguished road
Unhappy Memory Leak with Navigation Controller

This is a very simple test code to debug a very mystifying leak. When I run this code using Xcode's leak tool I get two leak objects ( _NSArrayM). The commented line below shows my leak source but I just fail to understand why I get this leak. All allocs in this code have been properly released.
Only way I can get rid of the leak is if I build my viewcontrollers using Interface Builder.
Any clue will be greatly appreciated. I am sure I am missing something very simple here. Anybody any ideas??

P.S using SDK 4.0

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {

// Override point for customization after application launch.

UIViewController *VC1 = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
VC1.title =@"First";
UINavigationController *nvc1 =[[UINavigationController alloc]init];
[nvc1 initWithRootViewController:VC1]; // Source of LEAK 1 !!!


UIViewController *VC2 = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
VC2.title =@"Second";
UINavigationController *nvc2 =[[UINavigationController alloc]init];
[nvc2 initWithRootViewController:VC2]; // Source of LEAK 2 !!!

// Add the tab bar controller's view to the window and display.

tabBarController.viewControllers = [NSArray arrayWithObjects:nvc1,nvc2, nil];


[nvc1 release];
[nvc2 release];
[VC1 release];
[VC2 release];

// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

return YES;
}
NJ1 is offline   Reply With Quote
Old 12-20-2010, 01:47 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you are initializing 2 times, so you have the leak. Just do_

UINavigationController *nvc1 =[[UINavigationController alloc]initWithRootViewController:VC1];

and same for the 2nd
__________________
dany_dev is offline   Reply With Quote
Old 12-20-2010, 02:01 PM   #3 (permalink)
NJ1
Registered Member
 
Join Date: Dec 2010
Posts: 4
NJ1 is on a distinguished road
Default

Thanks! That was a easy fix! Moral of the story here: never rely only on balancing allocs/retains/releases.


Quote:
Originally Posted by dany88 View Post
you are initializing 2 times, so you have the leak. Just do_

UINavigationController *nvc1 =[[UINavigationController alloc]initWithRootViewController:VC1];

and same for the 2nd
NJ1 is offline   Reply With Quote
Reply

Bookmarks

Tags
leak, navigation controller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 398
9 members and 389 guests
chemistry, daudrizek, HemiMG, jeroenkeij, Kirkout, PavelMik, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0