tabBar and memory issue?

Discussion in 'iOS Programming' started by MACloop, Mar 18, 2010.

  1. MACloop macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #1
    Hello,
    I use a combination of a tabBar and a navigationcontroller based on
    this example. Testing my app in the Leaks-tool, it indicates a leak in my appDelegate after that where I have defined my 4 navigation controllers. I have marked the content red where the leak is supposed to be. My problem is that I do not know why my app is leaking here? Any ideas? What should I be seaching for? It leaks 128 Bytes if that may be some indication here...

    Thanks in advance!
    MACloop

    Code:
    ...
    [COLOR="DarkGreen"]//code like this is added 4 times[/COLOR]
    TableViewController *tableViewController;
    	tableViewController = [[TableViewController alloc] initWithNibName:@"tableViewController" bundle:nil];
    	localNavigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
    	localNavigationController.navigationBar.tintColor = [UIColor lightGrayColor];
    	[localNavigationController.tabBarItem initWithTitle:@"Table" image:[UIImage imageNamed:@"some_pic.png"] tag:4];
    	[localControllersArray addObject:localNavigationController];
    	[COLOR="Red"][localNavigationController release];
    	[tableViewController release];
    ...
    
    [COLOR="DarkGreen"]//the tabBarController is retained in the .h file and is released in the dealloc method[/COLOR]
    	tabBarController.viewControllers = localControllersArray;
    	[COLOR="Red"][localControllersArray release];[/COLOR]
    	[window addSubview:tabBarController.view];
    
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    You have to show us the code where localControllersArray is assigned its value.

    No one can tell whether a release is appropriate without seeing how the object was obtained.
     
  3. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #3
    ok, this is how it looks like:
    Code:
    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
    alloc is doen once and retain is done once...
    MACloop
     
  4. jhurley macrumors newbie

    Joined:
    Feb 2, 2010
    #4
    you call alloc then retain it? Sounds like it probably has a retain count that's too high to actually be released. What happens if you don't retain it?

    Also is that a deep or a shallow copy happening there? You might end up with a bad access or something once the localControllersArray is released properly.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    Now post the code where the retain is done once.
     
  6. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #6
    ups...sorry :eek: it should of course have been:
    alloc once and RELEASE once...my mistake. I do not retain it I alloc and when it is added to the navigation I release it... As I can see it: alloc is +1 release is -1 making the sum 0.... hmmm?
    MACloop
     

Share This Page