Re: NSMutableDictionary crashing?
Re: NSMutableDictionary crashing?
- Subject: Re: NSMutableDictionary crashing?
- From: Marcel Weiher <email@hidden>
- Date: Thu, 2 Jan 2003 15:57:40 +0100
Incidentally, the "description" problem is actually very similar to the
"object-graph-archiving"-problem, and the "proper" solution consists of
having a type of context/visitor object that traverses the object
graph, printing out descriptions AND keeping track of objects already
seen.
The FilterStream framework that is part of MPWFoundation is perfect for
this sort of thing, beceause it encapsulates tree/graph iteration, with
the filter-stream being the place to keep track of already-seen objects
or other contextual information. In fact, I have a description-stream
that can handle cyclic structures, but it is currently part of a
private framework based on MPWFoundation. If there is demand, I can
push this down to MPWFoundation for public consumption.
Marcel
On Thursday, January 2, 2003, at 12:32 Uhr, Philippe Mougin wrote:
It is perfectly possible to use this kind of parent-child relationship
in an NSDictionary. However, doing this creates a cycle in the object
graph, and some methods, like NSDictionarys -description, are not
safe in this situation.
In your case, you ask for the description of the parent dictionary.
Since the description of a dictionary contains the description of the
objects referenced by the dictionary, the -description method called
on the parent dictionary will itself call -description on the child
dictionary, which will itself call -description on the parent and son
on. We are stuck in an infinite recursion. At some point, memory is
exhausted and the application crashes.
This is a limitation of NSDictionarys -description method (BTW, the
same limitation exists for the other Cocoa collection classes) and it
should be documented as such. This is not a problem unique to Cocoa.
Most object-oriented frameworks (Java , Smalltalk) have the same
problem with their own description methods.
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.