Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As already mentioned in other answers, you should pass an <code>autorelease</code>d instance to the setter like this:</p> <pre><code>[self setMediaSources: [[[MediaSources alloc] init] autorelease]]; </code></pre> <p>The crash you're seeing as a result of doing this seems to stem from the fact that you are doing background processing in <code>checkForMediaSourceUpdates</code>. If you want to do background processing in this method, you should ensure that <code>self</code> remains valid for the entire duration of the background task. It is perfectly valid to manually call <code>[self retain];</code> at the start and <code>[self release];</code> at the end. (Note: <code>GCD</code> blocks automatically retain/release <code>self</code> object if you're referencing it from within the block).</p> <p>EDIT: I hope you know the problem now, <a href="https://stackoverflow.com/users/773625/mau">mAu</a> called it. There is only one retain count (by <code>RootViewController</code> object) on <code>MediaSources</code> instance when a request is being executed. Before the request finishes, you call the method again, resulting in the <code>MediaSources</code> object being released. So when the request finishes, and <code>NSNotification</code> tries to send the callback message, app crashes since the observer instance has disappeared. </p> <p>There are two ways to resolve this (use whichever is more appropriate for your case): </p> <ol> <li>Either add <code>[self retain];</code> in <code>checkForMediaSourceUpdates</code> and <code>[self release];</code> at the end of <code>checkForMediaSourceUpdatesDownloadFinished:</code> </li> <li>Or, add <code>[[NSNotificationCenter defaultCenter] removeObserver: self]</code> in <code>-[MediaSources dealloc]</code>. </li> </ol> <p>Btw, you should think about <a href="https://stackoverflow.com/a/16677223/440060"><code>why do you need to allocate a new MediaSource on every call to getSelectedMediaSources?</code></a> and why you're starting a new request every time when you potentially have a running request. There is something very wrong with your design. </p>
 

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