• 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: Quincey Morris <email@hidden>
  • Date: Mon, 13 May 2013 22:09:02 -0700

On May 13, 2013, at 21:30 , Andy Lee <email@hidden> wrote:

> I believe ARC keeps it alive by virtue of self being a strong reference.

It isn't, not exactly. According to section 7.3 of the Clang ARC spec:

"The self parameter variable of an Objective-C method is never actually retained by the implementation. It is undefined behavior, or at least dangerous, to cause an object to be deallocated during a message send to that object."

This is the case when the receiver of the method invocation is itself a strong reference. If it's actually a __weak reference, it *is* retained for the duration of the method execution, because of the rules for retention of __weak objects used in expressions.

> I did a quick test and found that if I do
>
> - (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.

I suspect it works because the ARC implementation is "suboptimal", in the sense that it's causing self to be autoreleased as a result of being used in a later expression. If the implementation ever improved to avoid using autorelease, I'd expect it to start crashing in this scenario.

_______________________________________________

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

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>)

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