views:

28

answers:

1

I have an NSDictionary. It holds several objects, including an array of child NSDictionaries, each of which have an object keyed as @"Parent" that point back to the parent NSDictionary.

This circular reference breaks the ability to inspect the object with a classic call like:

NSLog(@"%@", [myDictionary description]);

Would anyone be so kind as to recommend a workaround for inspecting the object?

+1  A: 

Could you create your own description method in a category on NSDictionary and print out the contents manually rather than relying on the dictionary's description method?

There could be a bigger problem at hand here, in that dictionaries retain their contents. If you're adding an object to a dictionary, it gets retained, and then if you're adding the containing dictionary to the "sub" dictionary, it retains its parent. This will probably result in a retain cycle and probably prevent any of the objects getting deallocated.

From "Cocoa Programming for Mac OS X" by Aaron Hillegass:

If object X retains object Y, and Y retains X, the objects will never be deallocated. This situation is known as a retain cycle. A retain cycle can allow large islands of garbage to accumulate in your application's memory space.

Jasarien
Thanks for that note about retain cycles. I hadn't been alerted to that gotcha before. You've set me off on a reading binge to learn more.
baudot