简体   繁体   中英

Large Memory Leak Using Reachability

Using Instruments on the device it detects a 3.50 KB memory leak using Apple's Reachability 2.0 code in my app. The Leaked Object is GeneralBlock-3584. The leaks tool points to the following code:

- (BOOL) startNotifer
{
    BOOL retVal = NO;
    SCNetworkReachabilityContext    context = {0, self, NULL, NULL, NULL};
    if(SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context))
    {
        // THIS IS LINE OF CODE WHERE THE LEAK OCCURS:
        if(SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode))
        {
            retVal = YES;
        }
    }
    return retVal;
}

I'm pretty much using the Reachability example straight from the Apple example code so I can't figure out why this is happening or how I fix it.

根据开发人员论坛上的官方Apple声明(请查看http://devforums.apple.com ,并介意您的NDAs), GeneralBlock-3584泄漏, 不是真正的泄漏 ,实际上是仪器中的错误。

Try wrapping your Reachability object with NSAutoReleasePool. If it still exist try narrowing done towards the Leak with the autoreleasepool.

I think this is a similar problem to this question . Actually it seems that its a Bug within CFNetwork and it depends on the OS, so there is no workaround. Apple has to fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM