Re: views removed from their superviews are automaticallyreleased?
Re: views removed from their superviews are automaticallyreleased?
- Subject: Re: views removed from their superviews are automaticallyreleased?
- From: Michael Gersten <email@hidden>
- Date: Sun, 07 Apr 2002 23:27:38 -0700
Something to worry about.
This makes sense:
Lance Bland wrote:
>
>
On Wednesday, March 20, 2002, at 05:45 AM, Andrea Perego wrote:
>
>
> and the retain count isn't changed. Maybe there is something obvious
>
> I'm missing here; anyway, to provide some more info to anyone that
>
> might get intrigued by this puzzle:
>
>
Yes, that is true. I think that is an "implementation detail" and not
>
documented (at least last time I checked) ...
>
>
The view is deallocated on the run loop because it has to mix with
>
notifications and other things. To test that just place a NSLog() inside
>
the view's dealloc method. It will be called later on. Of course, I
>
didn't design that feature and I am just surmising why it is happening
>
the way it does.
>
>
-lance
But this worries me
>
The view was held in the superview array of subviews. This object when
>
removed from the array will be autoreleased. You retain count will not go
>
down until the AutoReleasePool is released - next time through the run loop.
>
>
Regards,
>
Chris.
>
>
--
>
Chris Rudolph, Apple Computer, Inc.
If it really has to mix with notifications and other things, and it really is autoreleased because "it has to last until the next runloop cycle", what if the test code is modified to say
NSLog(@"before removing from superv. retcount for view=%d",[paramOptionsView retainCount]);
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[paramOptionsView removeFromSuperview];
[pool release];
}
// NSLog(@"after removing from superv. retcount for view=%d",[paramOptionsView retainCount]);
Which is perfectly valid; but now, anything that was autoreleased in removeFromSuperview won't be able to deal with anything that happens between now and the runloop recycle.
I don't recall seeing an explicit "release at the next runloop cycle" method, and autorelease isn't guaranteed to last that long. Yet it is (apprently) autoreleased, not released, so someone must have wanted it to stay around a little bit longer for some reason, right?
Otherwise, why is it autoreleased and not released?
Michael
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.