Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand it correctly you just need to do [whateverConnection cancel] in your viewDidUnload or dealloc method. This cancels the connection. It is almost the same if you have a custom downloader object for example for some large image that uses NSURLConnection. Make a cancel method for your class (that cancels the connection and releases it) and invoke it in your controller's dealloc method. You should also use a bool flag something like wasCanceled and do not invoke any method from your custom object's delegate if wasCanceled was set from your cancel method. (You only have a weak pointer to your delegate so it is probably released already when some other object invokes your cancel method). I assume that the delegate for your custom object is the view controller. I had several downloaders like this and it worked ok, without leaks even if I quickly canceled a download.</p> <pre><code>@interface CompaniesDownloader : NSObject /*&lt;NSXMLParserDelegate&gt;*/ { id&lt;CompaniesDownloaderDelegate&gt; delegate; //a view controller is the delegate NSMutableArray *companies; BOOL isWorking; BOOL wasCanceled; @private //url connection object NSURLConnection *companiesConnection; //this is where i put the binary data that gets transformed into xml NSMutableData *webData; //temporary string used when parsing xml NSMutableString *tmpString; //temporary company used when parsing xml Company *tmpCompany; } </code></pre> <p>In the implementation:</p> <pre><code>-(void) cancel { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible: FALSE]; wasCanceled = TRUE; [companiesConnection cancel]; [webData release]; webData = nil; self.companiesConnection = nil; //OR [companiesConnection release]; companiesConnection=nil; isWorking = FALSE; } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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