开发者

Why is this code producing an memory leak?

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];
    [开发者_StackOverflow中文版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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜