Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all try simplifying your code. Things I did:</p> <ul> <li>Remove the outer dispatch_async. This is not needed, your <code>sendAsynchronousRequest</code> is async already. This also removes the need another <code>__block</code> variable on the queue. </li> <li>You create an image named <code>pImg</code> from the received <code>pData</code>, then convert that back to <code>NSData</code> of type png, and later create another image <code>pImage</code> from that again. Instead of converting over and over, just reuse the first image. You could even write the original <code>pData</code> to disk (unless you really want the png format on disk).</li> </ul> <p>I didn't compile the code below myself, so it might contain a few mistakes. But it is a simpler version that might help solve the leak.</p> <pre><code>- (void) downloadImageInBackgroundWithURL:(NSString*)szUrl { __block typeof(self) bSelf = self; NSAutoreleasePool *pAutoreleasePool = [[NSAutoreleasePool alloc] init]; NSURLRequest *pRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:szUrl] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:URL_REQUEST_TIMEOUT]; [NSURLConnection sendAsynchronousRequest:pRequest queue:m_pRequestQueue completionHandler:^(NSURLResponse *pResponse, NSData *pData, NSError *pError) { NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init]; if (pError) { // TODO: handle error return; } // convert image to png format __block UIImage *pImg = [UIImage imageWithData:pData]; // possibly just write pData to disk NSData *pDataPng = UIImagePNGRepresentation(pImg); bool bSaved = [[NSFileManager defaultManager] createFileAtPath:szCacheFile contents:pDataPng attributes:nil]; dispatch_sync( dispatch_get_main_queue(), ^ { // display the image in var pImg }); }]; [pAutoreleasePool drain]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload