我創建了一個從網上下載圖像的類。問題是它有一個內存泄漏。因爲這已被多次調用。所有下載的圖像都使用此方法調用。由於有無限的圖像來源,泄漏正在上升。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