CFNetwork / NSURLConnection leak

前端 未结 2 1599
慢半拍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条回答
  •  猫巷女王i
    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.

提交回复
热议问题