[Openmcl-devel] cocoa bridge memory management changes?

Raffael Cavallaro raffaelcavallaro at mac.com
Fri Sep 24 13:48:18 PDT 2010


On Sep 24, 2010, at 4:29 PM, Paul Krueger wrote:

> Yep, I think Willem hit it on the head.

No, he hasn't.

> If you use a convenience constructor, then you don't own the object returned and so the memory leak is avoided.

I know about convenience constructors. In fact, I posted about them about a month ago to this very list in response to a post of yours:

"Convenience methods (i.e., any object creation that doesn't involve an explicit alloc, or copy) generally return autoreleased objects, so you need to have a pool in place or they'll just leak."

> Of course you'd better make sure that you retain that object yourself

I do retain it.

Then, when the window is closed, I call release on it.

If I allocate it with make-instance, it leaks.

If I allocate it with #/dataWithContentsOfFile: it does not.
If I allocate it with (#/initWithContentsOfFile: (#/alloc ns:ns-data) it does not  (so using a convenience constructor has nothing to do with it - and yes, I only call retain on the autoreleased object not the alloced one).

Since it leaks only when allocated with make-instance, I conclude that there was a bug recently introduced in make-instance for cocoa classes.

> if you need it beyond the end of the current autorelease pool. 


warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro at me.com








More information about the Openmcl-devel mailing list