开发者

-[NSString componentsSeparatedByString:] leak

I have the following code:

NSString *indexText = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (indexText==nil) {
    [indexText release];
    indexText = [[NSString alloc] initWithData:data e开发者_Go百科ncoding:NSASCIIStringEncoding];
}
[data release];
NSAutoreleasePool *innerPool = [NSAutoreleasePool new];
NSArray *packageList = [indexText componentsSeparatedByString:@"\n\n"]; //if commented out, there's no leak
[indexText release];
[innerPool drain];

I'm performing a componentsSeparatedByString: on indexText, but I leak quite a bit of memory, despite that fact that packageList is autoreleased (proven by the fact that the code crashes if I try to release it again). When I comment out the line with componentsSeparatedByString:, the leak disappears.

By the way, I'm viewing memory usage in Activity Monitor whilst running iPhone Simulator; Instruments doesn't detect a leak. Is the leak just an illusion, a peculiarity of the Simulator?


There is no way that memory could have really leaked, componentsSeperatedByString: returns an autoreleased NSArray.

Trust Instruments when it comes to these things.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜