[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sending notifications in -dealloc

From: Richard Frith-Macdonald
Subject: Re: sending notifications in -dealloc
Date: Fri, 31 May 2002 15:48:40 +0100

On Friday, May 31, 2002, at 03:16 PM, Helge Hess wrote:

Helge Hess wrote:
This doesn't work on gstep-base, because the NSNotification created retains and afterwards releases the "object:self". This somehow results in a duplicate call to -dealloc (because the RC apparently reaches "0" twice). Is anyone aware of differences with regards to RC in -dealloc or has any other ideas ?

some more info, NSObject -release looks like this in libFoundation:
    if (NSExtraRefCount(self) == 1)
        [self dealloc];

and like that in gstep-base:
  if (NSDecrementExtraRefCountWasZero(self))
          [self dealloc];

(some code removed).

Actually I think that libFoundation is correct (and apparently it's implemented in the same way in MacOSX Foundation, I'll check that in the evening at home).

Gstep-base is implemented like it's written down in the documentation "If anObject didn't have an extra reference count, it returns YES, indicating that the object should be deallocated (with dealloc)". But this breaks if the count isn't checked (resulting unnecessarily in multiple -deallocs).

Opinions ?

While GNUstep is of course 'right' :-) (ie as specified/documented), but we want compatibility.

I think that the fact that NSDecrementExtraRefCountWasZero() returns a value implies it is intended to be used - which suggests that the libFoundation behavior is not quite in line
with MacOS-X either.

Perhaps NSDecrementExtraRefCountWasZero() and NSIncrementExtraRefCount() should simply not operate once the extra ref count goes to (unsigned)-1 (with the former returning NO) ?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]