Re: PDFOutline memory management
Re: PDFOutline memory management
- Subject: Re: PDFOutline memory management
- From: "Adam R. Maxwell" <email@hidden>
- Date: Tue, 17 Apr 2007 18:16:09 -0700
On Apr 17, 2007, at 13:33, John Calhoun wrote:
On Apr 16, 2007, at 8:39 PM, Adam R. Maxwell wrote:
I was checking over some code for memory leaks with MallocDebug,
and discovered an NSOutlineView datasource method that retains an
object from a PDFOutline instance variable before returning it, but
never releases it. Removing the retains causes a crash
On Tiger, you're right removing the retain will cause a crash.
On Leopard, you do not need to retain.
Thanks; I noticed that, and it's good to know it's intentional.
[...]
I didn't stop to try any code, but it seems to me a subclass of
PDFOutline might solve the issue for Tiger. It seems you could keep
your own instance variable to hold the children (an
NSMutableArray). You could override -[PDFOutline childAtIndex:] and
when first called for a child (you array is NULL), allocate your
array and call -[super childAtIndex:] for each child (-[PDFOutline
numberOfChildren:]). Once populated, you can simply return the
retained instance from your array. Of course at dealloc() you need
to release your array.
I tried that, but unfortunately it only works for the top-level
outline objects. Their children are still created using the base class.
I did come up with a self-contained workaround using poseAsClass: and
a static dictionary to add a pseudo-ivar array to each PDFOutline
instance, but it also requires overriding the private -[PDFOutline
initWithDocument:outline:] method that is (apparently?) used to create
children. Not very gratifying.
In the end, I think just adding each ephemeral child object to an
array before returning it from the outline datasource method is the
safest option, then just releasing that when the datasource deallocs.
It wastes a bunch of memory, but at least it can be reclaimed when
closing the window.
thanks,
Adam
_______________________________________________
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