Re: Changing Subview Order Prevents Dragging
Re: Changing Subview Order Prevents Dragging
- Subject: Re: Changing Subview Order Prevents Dragging
- From: Roland King <email@hidden>
- Date: Tue, 14 May 2013 12:53:36 +0800
On 14 May, 2013, at 12:30 PM, Andy Lee <email@hidden> wrote:
> On May 13, 2013, at 11:38 PM, Quincey Morris <email@hidden> wrote:
>> On May 13, 2013, at 19:41 , Graham Cox <email@hidden> wrote:
>>
>>> When you call -removeFromSuperview, the view is deleted, as there are no more references to it. The other methods are not called because the object ceases to exist.
>>
>> I believe your warning is apposite, but is not actually the cause of Tom's problem. After removing the view, his code adds it back again. If the view had already been deallocated, you'd expect a pretty big crash pretty soon (though not necessarily immediately).
>>
>> My guess is that the removed view is still retained by something,
>
> I believe ARC keeps it alive by virtue of self being a strong reference. 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. 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 ]. 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.
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.
_______________________________________________
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