• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing Subview Order Prevents Dragging
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing Subview Order Prevents Dragging


  • Subject: Re: Changing Subview Order Prevents Dragging
  • From: Andy Lee <email@hidden>
  • Date: Tue, 14 May 2013 01:16:26 -0400

On May 14, 2013, at 12:53 AM, Roland King <email@hidden> 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 (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

  • Follow-Ups:
    • Re: Changing Subview Order Prevents Dragging
      • From: Andy Lee <email@hidden>
References: 
 >Changing Subview Order Prevents Dragging (From: Thomas Wetmore <email@hidden>)
 >Re: Changing Subview Order Prevents Dragging (From: Graham Cox <email@hidden>)
 >Re: Changing Subview Order Prevents Dragging (From: Quincey Morris <email@hidden>)
 >Re: Changing Subview Order Prevents Dragging (From: Andy Lee <email@hidden>)
 >Re: Changing Subview Order Prevents Dragging (From: Roland King <email@hidden>)

  • Prev by Date: Re: Window positioning and screen resizing
  • Next by Date: Re: Changing Subview Order Prevents Dragging
  • Previous by thread: Re: Changing Subview Order Prevents Dragging
  • Next by thread: Re: Changing Subview Order Prevents Dragging
  • Index(es):
    • Date
    • Thread