On Apr 24, 2009, at 5:09 PM, Andreas Grosam wrote:
model creates several other objects that will be stored in a dictionary which is also an ivar of model. The dictionary will be used as a parameter in a recursive method invocation, where its sub dictionaries will be processed. Well, and it seemed practically to me (probably after a 14 hours day) to insert references to model to some sub-dictionaries at some point of the process. Unluckily, inserting an object increases its retain count, so the model retained itself through the dictionary - and could never be dealloced ;)
So, once I found the error, I could fix it in 5 seconds.

Just curious, if GC would solve this kind of self-referencing issue.

Short answer: yes.

Any garbage collector worth the name will reclaim cycles of objects that point to each other, as long as none of them are referenced by any "really" live object. If there is no chain to the objects from global variables or the stack, then they'll die eventually.

Longer answer: yes, unless you build a trap using CFRetain or - [NSGarbageCollector disableCollectorForPointer].

Objective-C's garbage collector adds one more complication. Retain counts from CFRetain() still work: a CFRetained object will not be deleted. You can get into trouble if you have a cycle of objects, and one of them is CFRetained, and the balancing CFRelease() is in the finalizer of another object in the cycle. The finalizer won't get called because the object is referenced by a CFRetained object, and the CFRetained object won't get CFReleased because that other finalizer isn't called.


--
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to