I have created a class to download images from web. Issue is there is a memory leak in it. Since this has been called multiple times. All the images getting downloaded are being called using this method. Since there are unlimited source of images the leak is mounting up.
Stack Trace is not showing any leak from code except main.
Leaked Object: Malloc 144, 176, 128, 160 bytes.
Resposible Library: CFNetwork
Responsible Frame: createCanonicalURL
Stack Trace:
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
connection object is properly released.
This is also coming in Device too. Most of them say its a bug in NSURLConnection, some say there is work araound adn some say not
I have tried setting as most mentioned
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
but no use…
Please advice
Code
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];
}
Connection for image is getting released at connection did finish load and error.
I tried ASIHTTPRequest thenI encountered a badurl error. I checked the url It seemed to be of format http:/www.example.com instead of http://www.example.com later found out that the code
NSString * fullImagePath = [rootURLForImage stringByAppendingPathComponent:imagePath];
was the issue.
it was the one which was remoging the slash from http://
so changed my code to