首页 > 解决方案 > CFNetworkCopyProxiesForAutoConfigurationScript 导致许多内存泄漏

问题描述

CFNetworkCopyProxiesForAutoConfigurationScript是 Apple 的原生 API,在 CFNetwork 框架中定义。每当我调用此 API 时,此 API 都会留下许多内存泄漏,并且每次调用此 API 时它们都会不断堆积。我使用“Instruments”“View Memory Graph Heirarchy”选项找到了它也。最后,由于内存问题,它崩溃了。

下面是我正在运行的示例代码。

CFErrorRef err = NULL;
NSString *strURL = @"http://www.google.com";
CFStringRef tempPacdata = CFStringCreateCopy(kCFAllocatorDefault, (__bridge CFStringRef)pacFileData);
CFURLRef tempURLref = CFURLCreateWithString(kCFAllocatorDefault, (__bridge CFStringRef)strURL, nil);
CFArrayRef proxies = CFNetworkCopyProxiesForAutoConfigurationScript(tempPacdata, tempURLref, &err);

strURL = nil;
if (proxies != NULL)
{
CFRelease(proxies);
proxies = NULL;
}

if (tempPacdata != NULL)
{
CFRelease(tempPacdata);
tempPacdata = NULL;
}
if (tempURLref != NULL)
{
CFRelease(tempURLref);
tempURLref = NULL;
}

这是内存图的屏幕截图

有没有其他人面临这个问题并对此有任何补救措施?也欢迎任何随意的想法。

标签: iosobjective-cxcodecfnetwork

解决方案


推荐阅读