Notification from dealloc and overiding retain/release scheme
Notification from dealloc and overiding retain/release scheme
- Subject: Notification from dealloc and overiding retain/release scheme
- From: Gérard Iglesias <email@hidden>
- Date: Tue, 17 Sep 2002 13:59:30 +0200
Hello,
I made some search around this subject on the archive
And saw that it is not a good idea to send notification from the
dealloc method with self as the object parameter.
But I am working on code containing this kind of stuff, and it worked
very well until I fall on a new use where the object deallocated and
sending a notification is also overriding retain/release scheme.
if the release is coded like :
- (void)release
{
refCount--;
if (refCount == 0)
[self dealloc];
}
then we enter in a 'infinite loop' ;)
dealloc -> notification -> retain -> release-> dealloc -> notification
-> retain > release -> .....
Hopefully, notification release directly, not by autorelease, hence I
found almost quickly the problem (a lot of class and code in the code I
have to maintain...)
But this stuff does work very well with object that not override
release, it seems that we need to know that an object is dying:
- (void)release
{
refCount--;
if (![self isDying] && refCount == 0)
[self dealloc];
}
Seems to be costly not, I didn't find anything in the runtime? maybe an
hidden function.
I can send an example of this stuff...
Obviously I can solve the problem by sending the address of the object
as a number in the 'info dict' of the notification. But I am surprised
that it is not documented...
Sincerely
Gerard
_______________________________________________
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.