Run*_*oop 10 iphone cocoa-touch objective-c
在设备上运行仪器,我间歇性地在CFNetwork中引起3.5 KB的内存泄漏,负责的框架是"HostLookup_Master :: HostLookup ...."
我已经阅读了这个问题的一些问题,并分别尝试以下方法来修复泄漏:
在applicationDidFinishLaunching中包含以下内容:
NSURLCache*sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release];
在urlrequest中指定不从本地缓存加载.
以上都没有奏效.实例化连接的我的类不会泄漏,因为它的实例在下载数据时被释放.我通过使用Instruments确认该类的生物对象是0来验证这一点.
任何有关解决这一泄漏的建议都将不胜感激.
处理线程时, 3.5kb内存泄漏听起来很熟悉:
@implementation MyClass
+ (void)login
{
//MyClass *this = [[MyClass alloc] init]; // MEMORY LEAK
MyClass *this = [[[MyClass alloc] init] autorelease];
[NSThread detachNewThreadSelector:@selector(anotherThread)
toTarget:this
withObject:nil];
}
- (void)anotherThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self doStuff];
//[self release]; // MEMORY LEAK
[pool release];
}
@end
Run Code Online (Sandbox Code Playgroud)
每次登录都会产生 3.5kb 的泄漏。使用自动释放解决了这个问题。
| 归档时间: |
|
| 查看次数: |
2745 次 |
| 最近记录: |