title: Memory leak issue on NSURLConnection
body: <p>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.</p>
  
  <p>Stack Trace is not showing any leak from code except <strong>main</strong>.</p>
  
  <p><strong>Leaked Object:</strong> Malloc  144, 176, 128, 160 bytes. </p>
  
  <p><strong>Resposible Library:</strong> CFNetwork</p>
  
  <p><strong>Responsible Frame:</strong> createCanonicalURL</p>
  
  <p><strong>Stack Trace:</strong></p>
  
  <pre><code>   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&lt;XClientEvent, XClientEventParams&gt;*, 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
  </code></pre>
  
  <p>connection object is properly released. </p>
  
  <p>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</p>
  
  <p>I have tried setting as most mentioned </p>
  
  <pre><code>[[NSURLCache sharedURLCache] setMemoryCapacity:0];
  [[NSURLCache sharedURLCache] setDiskCapacity:0];
  </code></pre>
  
  <p>but no use...</p>
  
  <p>Please advice</p>
  
  <p>Code</p>
  
  <pre><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];
  
  
      }
  </code></pre>
  
  <p>Connection for image is getting released at connection did finish load and error.</p>