gnustep-dev
[Top][All Lists]
Advanced

[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:28:40 +0100

On Friday, May 31, 2002, at 02:37 PM, Helge Hess wrote:

Hi,

maybe someone has an obvious answer ... This code does work on MacOSX and libFoundation, but not on gstep-base:
---snip---
- (void)dealloc {
  ..
  nc = [NSNotificationCenter defaultCenter];
  [nc postNotificationName:@"ContextWillDeallocate" object:self];
  ..
  [super dealloc];
}
---snap---

I do this for weak references where I want to notify other observers that the context is deallocated (they will reset their non-retained pointer) ...

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 ?

Interesting ... GNUstep implements the documented behavior -
retain increments the retain count (by calling NSIncrementExtraReefCount(), release decrements it (by calling NSDecrementExtraRefCountWasZero()), and when it reaches zero dealloc is called.

So a retain within the dealloc will increment the retain count to 1, the release will decrement it to
zero, and dealloc will get called again.

Presumably MacOS-X actually differs slightly from the documented behavior and does something like ignoring
any retain/release when the retain count is zero?
We could change GNUstep to work the same way for compatibility - though I think it would be a little less
efficient when built to user a map table for the extra reference counts.




reply via email to

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