开发者

CFNetwork / NSURLConnection leak

开发者 https://www.devze.com 2022-12-23 00:27 出处:网络
Running instruments on the device, I intermittently incur a memory leak of exactly 3.5 KB in CFNetwork, the responsible frame being \"HostLookup_Maste开发者_如何转开发r::HostLookup....\"

Running instruments on the device, I intermittently incur a memory leak of exactly 3.5 KB in CFNetwork, the responsible frame being "HostLookup_Maste开发者_如何转开发r::HostLookup...."

I have read a number of questions re this issue and have separately tried the following to fix the leak:

  1. Included the following in applicationDidFinishLaunching:

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release];

  2. Specified in the urlrequest not to load from the local cache.

None of the above worked. My class that instantiates the connections does not leak as its instances are released when data has been downloaded. I have verified this by confirming the the living objects of the class is 0 using Instruments.

Any advice on addressing this leak would be greatly appreciated.


That 3.5kb memory leak sounds familiar, had that when dealing with threads:

@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

Every login created 3.5kb leak. Using autorelease solved the problem.


It seems that apple might be aware of the 3.5k leak related to CFNetwork usage and may have been reported as a bug already.

0

精彩评论

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

关注公众号