Note that there are some explanatory texts on larger screens.

plurals
  1. POEXC_BAD_ACCESS when setting synthesized (retained) property to nil
    text
    copied!<p>I get a bad access (objc_msgsend) when calling this line of code:</p> <pre><code>self.currentGameTeam = nil; </code></pre> <p>Where "currentGameTeam" is defined in the interface for a class called "MCState" as:</p> <pre><code>MNAvailableTeamContext *currentGameTeam; </code></pre> <p>And I synthesize a property for it:</p> <pre><code>@property (retain) MNAvailableTeamContext *currentGameTeam; </code></pre> <p>After setting NSZombieEnabled the console shows:</p> <pre><code>*** -[MNAvailableTeamContext release]: message sent to deallocated instance 0x5b3eba0 </code></pre> <p>And the debugger trace shows that it comes from within the synthesized setter code:</p> <pre><code>#3 0x0001fa96 in -[MCState setCurrentGameTeam:] at MCState.m:44 </code></pre> <p>I've looked at several other questions and threads and I can't find an answer that applies to my case. I don't understand why there would be a bad access if I've synthesized the property and I'm setting it to nil. What is especially odd is that there are at least 3 other properties in MCState which are defined and used in the exact same way as currentGameTeam, with the only difference being that they are different types:</p> <pre><code>MNUserContext *storedUser; MNActiveGameContext *storedGame; MNAvailableUserContext *storedGameUser; MNAvailableTeamContext *storedGameTeam; </code></pre> <p>and</p> <pre><code>@property (retain) MNUserContext *currentUser; @property (retain) MNActiveGameContext *currentGame; @property (retain) MNAvailableUserContext *currentGameUser; @property (retain) MNAvailableTeamContext *currentGameTeam; </code></pre> <p>and</p> <pre><code>@synthesize currentUser; @synthesize currentGame; @synthesize currentGameUser; @synthesize currentGameTeam; </code></pre> <p>finally</p> <pre><code>self.currentUser = userContext; self.currentGame = nil; self.currentGameUser = nil; self.currentGameTeam = nil; // Error occurs here </code></pre> <p>The rest of these all act normally - only currentGameTeam gives me trouble. Any ideas?</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