即使使用CFRelease,SCNetworkReachability也会泄漏

时间:2013-10-17 13:28:01

标签: ios memory-management automatic-ref-counting memory-leaks

我在线阅读了一个教程,了解iOS设备是否已连接到互联网。它工作正常,但无论何时调用它都会分配越来越多的内存,并且它经常被调用。此外,我正在使用ARC,并分析该项目恢复干净

 - (BOOL) connectedToNetwork {
    // Create zero addy
    struct sockaddr_in zeroAddress;
    bzero(&zeroAddress, sizeof(zeroAddress));
    zeroAddress.sin_len = sizeof(zeroAddress);
    zeroAddress.sin_family = AF_INET;

    // Recover reachability flags
    SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
    SCNetworkReachabilityFlags flags;
    if(defaultRouteReachability){
       bool didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
       CFRelease(defaultRouteReachability);

       if (!didRetrieveFlags) { 
          return NO;
       }
       BOOL isReachable = flags & kSCNetworkFlagsReachable;
       BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
       return (isReachable && !needsConnection) ? YES : NO;
    }
    return false;
 }

似乎是在SCNetworkFlagsReachableSCNetworkReachabilityCreateWithAddress上进行分配,即使我调用CFRelease它仍然会分配越来越多的内存。

0 个答案:

没有答案