• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: observing dealloc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: observing dealloc


  • Subject: Re: observing dealloc
  • From: Diederik Hoogenboom <email@hidden>
  • Date: Mon, 28 May 2007 19:54:06 +0200

Ken,

Use [object observationInfo] which returns an array with dictionaries, one for each observer:

e.g.:

<NSCFArray 0x3cacf0>(
<NSKeyValueObservance: Observer: 0x3ba820, Key path: arrangedObjects, Include old: NO, Include new: NO, Context: 0x0, Property: 0x3be940>,
<NSKeyValueObservance: Observer: 0x3bdca0, Key path: arrangedObjects.name, Include old: NO, Include new: NO, Context: 0x0, Property: 0x3ca590>
)



- Diederik

--
Diederik Hoogenboom
Obvious Matter - DiskLibrary for Mac
http://www.obviousmatter.com



On 28-mei-2007, at 19:25, Ken Tozier wrote:

Upon more thought, I could do what I want if there is any way for an object to get it's list of observers. Is there any way to do that?


On May 28, 2007, at 12:45 PM, Ken Tozier wrote:


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:
40comcast.net


This email sent to email@hidden

_______________________________________________

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:
40obviousmatter.com


This email sent to email@hidden


_______________________________________________

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


  • Follow-Ups:
    • Re: observing dealloc
      • From: Jim Correia <email@hidden>
References: 
 >observing dealloc (From: Ken Tozier <email@hidden>)
 >Re: observing dealloc (From: Jim Correia <email@hidden>)
 >Re: observing dealloc (From: Ken Tozier <email@hidden>)
 >Re: observing dealloc (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: observing dealloc
  • Next by Date: Re: observing dealloc
  • Previous by thread: Re: observing dealloc
  • Next by thread: Re: observing dealloc
  • Index(es):
    • Date
    • Thread