Re: observing dealloc
Re: observing dealloc
- Subject: Re: observing dealloc
- From: Ken Tozier <email@hidden>
- Date: Mon, 28 May 2007 12:45:18 -0400
On May 28, 2007, at 12:19 PM, Jim Correia wrote:
I think you are going to have to be more specific about what it is
you are trying to do, rather than the mechanics by which you think
you should do it.
In particular, since NSDictionary copies its keys, trying to
observe the object lifetime of the original instance isn't going to
do you any good.
I'm writing a base class and want to include a built in capability
for contextual globals. For example:
@implementation MyObject
NSMutableDictionary *gGlobals = nil;
+ (void) initialize
{
if (gGlobals == nil)
{
gGlobals = [[NSMutableDictionary alloc] init];
}
}
+ (NSMutableDictionary *) globalsForKey:(id) inKey
{
NSMutableDictionary *result = [gGlobals objectForKey: inKey];
if (result == nil)
{
result = [NSMutableDictionary dictionary];
[ gGlobals setObject: result
forKey: inKey];
}
return result;
}
@end
In the above, the key is an object that serves as a context for a set
of globals and when that context disappears, I'd like to remove all
associated globals as well.
On May 28, 2007, at 12:23 PM, Shawn Erickson wrote:
You have two issues. 1) NSDictionary copies keys that you use and
2) NSDictionary holds a retain on those keys (related to issue 1).
So dealloc will not get called.
Ah yes, a catch 22.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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