开发者

Is the analyzer really trustworthy concerning the detection of memory leaks?

In my app delegate I have the following code snippet:

...

@synthesize model = _model;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...

    // Allocate the model
    self.model = [[Model alloc] init];

    ...
}

- (void)dealloc
{
    [_model release];
    [super dealloc];
}

...

The XCode Analyzer reports a potential memory leak on the line after the allocation of the model (it did go away when I added an autorelease statement, so I guess it just got mixed up with the line numbers). Is th开发者_运维百科is truly a memory leak or is the analyzer confused? After all a release is done in the dealloc method. So is there a potential of a memory leak here and in which situations?

If that's so I guess the solution would be to add autorelase to the allocation.


It's a memory leak if the property is defined as retain because it has a retain count of 2 - once for alloc and once on assignment to the property - but you only release it once. Xcode does get confused about line numbers though.


Yes, it is trustworthy!

If you click on the blue arrow icon on the line where the analyzer shows a leak:

Is the analyzer really trustworthy concerning the detection of memory leaks?

it will give you more information about the leak, showing exactly where it originated, and in this case the reason why it appears on the next line:

Is the analyzer really trustworthy concerning the detection of memory leaks?


The static analyser is very trust worthy. after all ARC is completely based on it. It has to be good in order for iOS5 programming to work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜