Note that there are some explanatory texts on larger screens.

plurals
  1. POObject being released too early?
    primarykey
    data
    text
    <p>I've been hitting my head against a wall for 2 days now, trying to figure out what the heck is wrong with my code. So far, nothing. The only thing I've discovered is the fact that an object is trying to call release on itself and it hasn't been instantiated yet. (although, for some reason it doesn't happen 100% of the time, just whenever the heck it thinks)</p> <p>Let me explain the problem (maybe I'm overlooking something, I hope you guys can shed some light into my darkness)</p> <p>My model object</p> <pre><code>Person { NSString *name; NSNumber *age; } @property(nonatomic, retain) NSNumber* TheAge; @property(nonatomic, retain) NSString *TheName; </code></pre> <p>My implementation</p> <pre><code>@synthesize TheName = name; @synthesize TheAge = age; +(Person*)personFromDictionary:(NSDictionary*)dic { Person* newPerson = [[[Person alloc] init]autorelease]; newPerson.theAge = [dic objectForKey:kAge]; newPerson.theName = [dic objectForKey:kName]; return newPerson; } -(void)dealloc { self.TheAge = nil; self.TheName = nil; } </code></pre> <p>I have a "collector thread" that reads a JSON array from the server, downloads it and parses it into a dictionary. Every entry in the dictionary corresponds to a person object This thread is a different class simply using the Person model</p> <p>The thread does something like this (in an autorelease pool)</p> <pre><code>NSDictionary *parsedDict = download.returnValue; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Person *tmpPerson = personFromDictionary [entryDictionary setObject:tmpPerson forKey:kAge]; [pool release]; [self updateEntries:entryDictionary]; -(void)updateEntries:(NSMutableDictionary*)updatedDict { NSArray *keys = [updatedDict allKeys]; for(NSString *key in allKeys){ Person *entry = [updatedDict valueForKey:key]; [entriesLock lock]; [currentPersonEntries setObject:entry forKey:key]; [entriesLock unlock]; } } </code></pre> <p>When I get the crash (which happens randomly for some damn reason, I get the stack trace as follows</p> <p>person dealloc</p> <p>person setTheAge (bam crash)</p> <p>I'm guessing because the setter would look something like this</p> <pre><code>-(void)setTheAge:(NSString*)theAge { [theAge retain]; [age release]; // it doesn't exist for some reason??? age = theAge; } </code></pre> <p>How can I protect vs this type of thing?</p>
    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. 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