Tuesday, November 29, 2011

Note to self on overriding dealloc in Obj-C

I went through the chapter in Obj-C:TBNRG about ARC and retain cycles and got to the end with my head spinning. I understand what's going on but following which instances of what class own who is dizzying. The Objective-C style of having two files per class (one header file one implementation file) makes it hard to follow since you can't see everything at once. Well... maybe having everything in one big file isn't the way to go either.

Anyways, I intend on going through it again for good measure.

Something that had been bothering me is that in the classes you make for the example you override the dealloc method so that you can toss a print statement in to say when it's being deallocated (in an effort to show what actions on the data cause it to deallocate automatically). I realized that the implication would be that the data isn't actually getting deallocated! So, to the internets I go and I find that The Big Nerd Ranch has a forum for its books, wherein I find this:

http://forums.bignerdranch.com/viewtopic.php?f=151&t=3223

Basically: the magic of ARC saves you by somehow knowing to call the dealloc of the parent class (or the parent's parent class which inherits NSObject I think in the example). I don't like magic, but I'll roll with it for now.

No comments:

Post a Comment