Re: Need advice: Object ownership and threading issue, causing a rare crash.
Re: Need advice: Object ownership and threading issue, causing a rare crash.
- Subject: Re: Need advice: Object ownership and threading issue, causing a rare crash.
- From: Ken Thomases <email@hidden>
- Date: Tue, 07 May 2013 04:54:57 -0500
On May 6, 2013, at 5:26 PM, Motti Shneor wrote:
> Hello Ken, and so-many-thanks for the information.
You're welcome. More below…
> On 4 במאי 2013, at 07:24, Ken Thomases <email@hidden> wrote:
>
>> Honestly, I doubt that -dealloc is reentered. I suspect you've misdiagnosed what is happening or, perhaps, there's some other severe problem such as heap corruption that's leading to that. It *definitely* won't happen merely because two threads are racing in -release for the same object (assuming they are both entitled to release the object because they each have an ownership stake).
>
> Well, the crash-log provides a call-stack which quite clearly shows the "dealloc" re-enrered. Now I'm really puzzled, because if NSThread protected me against premature deallocation on its own, How on earth could I reach the "dealloc" before the thread was done?
Let me clarify. I doubt that -dealloc is reentered *for a given instance*. It's very possible that one instance of your class held (perhaps through a chain of other objects) the last strong reference to another instance of your class. So, during its -dealloc, it released that reference, causing the other instance to also deallocate. That would be consistent with the stack trace you describe. There would be two frames of -[YourClass dealloc] listed, but they would be for different instances.
Now, that shouldn't cause a crash in and of itself.
What does your -dealloc do?
Also, have you taken the easy steps to verify your memory management? Use the static analyzer (Build and Analyze) and clean up any problems it identifies (or understand them to the point where you're sure they're false positives). Run your app under the Zombies instrument.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden