我创建了一个从网上下载图像的类。问题是它有一个内存泄漏。因为这已被多次调用。所有下载的图像都使用此方法调用。由于有无限的图像来源,泄漏正在上升。NSURLConnection上的内存泄漏问题
堆栈跟踪没有显示代码泄漏,除了主要。
泄漏对象: Malloc 144,176,128,160字节。
Resposible库: CFNetwork的
负责任的框架: createCanonicalURL
堆栈跟踪:
0 CFNetwork createCanonicalURL
1 CFNetwork HTTPProtocol::_createMutableCanonicalRequest(__CFAllocator const*, _CFURLRequest const*, void const*)
2 CFNetwork HTTPProtocol::_createCanonicalRequest(__CFAllocator const*, _CFURLRequest const*, void const*)
3 CFNetwork HTTPProtocol::copyCanonicalRequest()
4 CFNetwork URLConnectionLoader::copyProtocolCanonicalRequest()
5 CFNetwork URLConnectionClient::getRequestForTransmission(unsigned char, _CFURLResponse*, _CFURLRequest const*, __CFError**)
6 CFNetwork URLConnectionClient::_clientWillSendRequest(_CFURLRequest const*, _CFURLResponse*, URLConnectionClient::ClientConnectionEventQueue*)
7 CFNetwork URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long)
8 CFNetwork URLConnectionClient::processEvents()
9 CFNetwork MultiplexerSource::perform()
10 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
11 CoreFoundation __CFRunLoopDoSources0
12 CoreFoundation __CFRunLoopRun
13 CoreFoundation CFRunLoopRunSpecific
14 CoreFoundation CFRunLoopRunInMode
15 GraphicsServices GSEventRunModal
16 GraphicsServices GSEventRun
17 UIKit UIApplicationMain
18 Interior News main /iPhone Ongoing Projces/WAN_Interiors/Latest_Interior_News_V_1_2/Latest_Interior_News/main.m:14
19 Interior News start
连接对象正常释放。
这也在Device中出现。他们大多表示,其在NSURLConnection的一个bug,有人说有工作araound ADN有人说没有
我已经尝试设置为最提到
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
,但没有用...
请咨询
代码
if (connectionForImage==nil)
{
NSString * fullImagePath = [rootURLForImage stringByAppendingPathComponent:imagePath];
NSString * trimedstring = [fullImagePath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString * percentEscapedUrl = [trimedstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Trimmed :%@",trimedstring);
NSLog(@"PercentEscaped %@",percentEscapedUrl);
NSURLRequest * imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:percentEscapedUrl] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:6.0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
connectionForImage =[[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];
}
连接用于图像越来越ř在连接时弹出完成加载和错误。
显示你的代码...或启用NSZombie ...并运行... – Rams 2012-02-23 05:16:35
NSZombieEnabled如何帮助跟踪泄漏 – 2012-02-23 05:38:13
您正在使用哪个版本的xcode。 – iamsult 2012-02-23 05:42:55