views:

173

answers:

2

The Leaks Instrument in Xcode shows me an memory leak here. I have commented the affected line which Leaks is complaining about. But I see no error in my memory management...

- (void)setupViewController {
    MyViewController *myVC = [[MyViewController alloc] init];

    UITabBarItem *tbi = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
    myVC.tabBarItem = tbi; // LEAK: 128 bytes

    self.myViewController = myVC;

    [myVC release];
    [tbi release];
}

I mean... tbi and myVC IS released at the end, and the alloc IS balanced. So what's wrong? I don't get it.

+3  A: 

if MyVc.tabBarItem is already set, whatever it's pointing at may not be deallocated properly, causing a leak.

patros
The tabbar property of myVC should be a property defined to retain. If you do that, the retention of objects assigned to the property will be maintained automatically.
TechZen
well, but tabBarItem is from Apple, not from me ;-) I didn't create any tabBarItem property for my View Controller. Apple did. It would be against the memory management rules if I manually release myVC.tabBarItem just because Apple has forgotten to do so, wouldn't it?
dontWatchMyProfile
`tabBarItem` is a property with `retain` semantics. It's very unlikely that there's a leak in the setter.
Nikolai Ruhe
+2  A: 

It just goes to show that at least one of the following statements is true:

  1. Instruments is not perfect and sometimes shows leaks where there aren't any (and vice versa).
  2. Apple's code is not bug-free.

In fact, both are true.

Ole Begemann