Re: What's most common cause of SIGSEGV and SIGBUS
Re: What's most common cause of SIGSEGV and SIGBUS
- Subject: Re: What's most common cause of SIGSEGV and SIGBUS
- From: Gwynne <email@hidden>
- Date: Sat, 13 Mar 2004 23:47:19 -0500
On Mar 13, 2004, at 11:35 PM, Ken Tozier wrote:
Simple question: are you sure your object is correctly retained? (the
first time it works because it has been autoreleased, the next time
the object has been deallocated and the code crashes).
It turns out that I was releasing the return from [aString
componentsSeparatedByString:delimString] inside a loop like so:
while (object = [enumerator nextObject])
{
kvParts = [object componentsSeparatedByString:@"="];
[keys addObject:[kvParts objectAtIndex:0]];
[values addObject:[kvParts objectAtIndex:1]];
[kvParts release]; // <- commenting out this line stops the crashes
}
Not releasing "kvParts" seems really leaky to me. Is this a real leak
or am I just not understanding how Cocoa memory management works?
You are obtaining "kvPorts" from NSString's
-componentsSeparatedByString: method. This method does not have "alloc"
or "copy" anywhere in it, so the object it returns is, by definition,
autoreleased. Autoreleased objects are placed in a list and freed every
time through your event loop (usually). If you release the object
yourself, the result is that the object is released twice, which
generally causes a crash. In summary, yes, you are misunderstanding
Cocoa memory management :).
-- Gwynne, key to the Code that runs us all
Formerly known as Sailor Quasar.
Email: email@hidden
Web:
http://musicimage.plasticchicken.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.