initWithContentsOfURL泄漏NSOperation子类中的内存。其他人看到这个?

时间:2009-12-03 02:54:19

标签: iphone cocoa-touch multithreading nsoperation

我一直在仪器上生活了几个小时,盯着令人费解的内存泄漏。我把它分离到我编写的NSOperation子类中的这一行代码:

NSData *myData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURLString]];

这将定期泄漏3500个字节。还有其他人看到这个吗?如果是这样,有解决方法吗?

提前致谢。

更新:

以下是我的NSOperation子类的main()主体中的相关代码部分:

- (void)main {

// ...

NSData *sequenceData = 
[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:concatenatedURLString]];

NSString *sequenceString = 
[[NSString alloc] initWithBytes:[sequenceData bytes] length:[sequenceData length] encoding:NSUTF8StringEncoding];

NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:
self.chromosome, @"chromosome",
[NSNumber numberWithInt:self.basepairStart], @"basepairStart", 
[NSNumber numberWithInt:self.basepairEnd], @"basepairEnd", 
sequenceData, @"sequenceData", 
sequenceString,  @"sequenceString", 
nil];

[sequenceData   release];
[sequenceString release];

[self.target performSelectorOnMainThread:self.action withObject:result waitUntilDone:NO];


}

正如您所见,sequenceData和sequenceString已正确发布。此外,我已经确认这个子类的所有ivars(染色体等)都是适当的内存管理。

-Doug

1 个答案:

答案 0 :(得分:0)

您必须释放或自动释放myData,否则会根据Cocoa Memory Management Rules

泄漏