开发者

iphone/ipad memory leaks instrument tool

In 开发者_JAVA百科order to try the memory leaks instrument tool, I create a view-based ipad application. It is very simple. I create a default view-based application. In the ViewController's loadView, I say

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {

    [super loadView];

    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, 768, 1004);
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    [view removeFromSuperview];
}

So, I create a view inside loadView, then add it to the root view, then remove it.

But the view is created in a method and I never release it.

So I think after loadView finishes, the created view is leaked right?

I used memory leaks instrument tool to check, it reports no leak at all.

Any one could pls explain it why?

thanks


The leaks tool -- either command line or the Allocations Instrument -- reports a leak as an object that is no longer referenced by anything. The problem, though, is that a stray pointer to the object may still be in memory somewhere, even if that memory will never be read again.

I.e. the leaks instrument is not 100% accurate and it strives to not give false positives (which are much more troublesome).

I generally use the Allocations instrument, go through the list of objects that are "live" at any given time and mentally justify their existence.

You are correct in that said code snippet will cause a leak of the UIView instance. If you were to build and analyze, I would expect that Xcode would identify the problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜