Re: ARC dealloc best pratice
Re: ARC dealloc best pratice
- Subject: Re: ARC dealloc best pratice
- From: Jonathan Mitchell <email@hidden>
- Date: Sat, 07 Feb 2015 22:50:17 +0000
> On 6 Feb 2015, at 17:34, Kyle Sluder <email@hidden> wrote:
>
> On Fri, Feb 6, 2015, at 08:48 AM, Jonathan Mitchell wrote:
>> So I want to have a best practice template to follow in my dealloc.
>
> Dealloc is too late for a lot of this stuff. I try to keep -dealloc as
> pure as possible; that is, -dealloc should only be concerned with memory
> management.
Returning briefly to the core point to this thread.
Sometimes, in order to access objects to be unobserved etc I may message self in my dealloc.
Am I playing with matches in the woodshed?
So, is the following correct under ARC in dealloc:
1. Dealloc is sent to each subclass prior to any manipulation of the retain state for its ivars.
2. The object graph is still intact during dealloc and may be safely navigated (assuming that I don’t zero out any references myself in dealloc).
3. What is not okay is to call any code path in dealloc that would cause self to be stored into a pointer that is subsequently dereferenced.
4. It is okay to call a code path that would cause an ivar/property to receive an additional strong reference (i.e.: the dealloc code causes an ivar that would otherwise have been deallocated to be retained)
I have no problem in recognising that it is trivially easy to screw things up in dealloc but it would help to know the boundaries a bit more clearly.
I think someone mentioned that dealloc was covered in some detail in a WWDC 2011 session but I haven’t been able to pin down just which one yet.
Thanks
Jonathan
_______________________________________________
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