On May 14, 2013, at 12:53 AM, Roland King <r...@rols.org> wrote: [...] >> - (void) mouseDown: (NSEvent*) event >> { >> NSView* superView = [self superview]; >> [self removeFromSuperview]; >> // [superView addSubview: self]; >> } >> >> ...then dealloc does in fact get called. But if I uncomment that one line, >> which references self, dealloc does not get called. This is good news -- I >> would want ARC to work regardless of whether it calls non-ARC code, and vice >> versa. >> > > well you have several lines in there which reference self, [ self superview ] > and [ self removeFromSuperview ].
I was thinking that if calling [self removeFromSuperview] removed the last reference to self, dealloc would have been called in both cases. Naturally I wouldn't expect self to have been dealloc'ed before that statement. > The only difference in the last one is that self is used as a parameter to a > call to another object and that may possibly be the difference. I fiddled a bit with it, adding calls that don't take arguments like [self description] and [self self]. There was no dealloc until just before the method exited, after those calls. It *seems* that merely referring to self, whether as receiver or argument, keeps it alive. However, I might just have been lucky. > And the LLVM documents talk about this, they say that self is not retained > during a method call. > > http://clang.llvm.org/docs/AutomaticReferenceCounting.html#self > > and discuss exactly this risk. Thanks. Just goes to show it's dangerous to guess too much -- in my case, that self is a strong reference -- from too little evidence. --Andy _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com