Hi,

What I initally did was exactly to log from the dealloc method of my node class. Experiencing that it never got called, I started to log from retain and release to try to get deeper into the problem.

I stumbled on the problem when integrating some C++ code into my cocoa project. Every node object in the NSMutableArray would hold a pointer to a quite large C++ representation of a 3D model. Each of these models allocated approc 0.5 mb of memory, and this show up quite signifaicantly in instruments when allocating and deallocating objects through the NSTreeController. Unfortunately, the memory consumption only goes up when allocating and never down when removing nodes because the dealloc method of the node is never called and my 3D model hence never deleted.

Funny enough, if I replace the TreeController with an Arraycontroller everything works as expected.

/Mads

On Nov 9, 2009, at 12:38 , Graham Cox wrote:


On 09/11/2009, at 10:31 PM, Mads Paulin wrote:

Adding a node object through this method creates a node object in the
document array member with a retain count of 2. The remove:sender method correctly removes the object from the document's array but only decrements the node object's retain count to 1 - meaning that the objects are never dealloc. As I see it, this is a memory leak in NSTreeController as all "my"
external references to the Node objects are lost.


You can't meaningfully debug by peeking at retain counts. Instead try logging from the -dealloc method if possible, or use the leaks Instrument to find out if the objects are really not being deallocated. There's no requirement that the retain count is actually decremented to 0 - the code may merely predict that it would be and call -dealloc, rather than actually doing it.

--Graham



_______________________________________________

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