CFNetwork / NSURLConnection leak

前端 未结 2 1579
慢半拍i
慢半拍i 2021-01-17 17:46

Running instruments on the device, I intermittently incur a memory leak of exactly 3.5 KB in CFNetwork, the responsible frame being \"HostLookup_Master::HostLookup....\"

相关标签:
2条回答
  • 2021-01-17 18:43

    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.

    0 讨论(0)
  • 2021-01-17 18:43

    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 讨论(0)
提交回复
热议问题