Re: NSBezierPath retain crash
Re: NSBezierPath retain crash
- Subject: Re: NSBezierPath retain crash
- From: Christopher Corbell <email@hidden>
- Date: Wed, 12 Nov 2003 10:43:16 -0800
On Nov 12, 2003, at 10:02 AM, Chad Harrison wrote:
I have an object which includes one instance of a NSBezierPath, but
when I try to do anything with the path (like transform or stroke), it
crashes - I though that since I am creating it with
bezierPathWithRect: rect, it was autoreleased and I did not have to
retain it. Even if I specifically retain and release it, it crashes.
I'm missing something here.
Review the Cocoa memory management docs again - autoreleased means
that the object is valid for the current call stack, but at any
time after the current stack returns the object may be
released from memory.
If you alloc, copy, or retain an object, it is not auto-released
and you can stash it away e.g. in a class member variable, and
release it when you're done.
If you use a method like bezierPathWithRect, stringWithCString, etc.
or otherwise obtain an autoreleased object, and want to use that
object persistently as a class member, you -must- call retain on the
object. (And then you're responsible for calling release or
autorelease on the object when you're done with it, e.g. you
replace it or the owning class is dealloc'd).
hth,
Christopher
=============================
Cider Factory Software, Inc.
http://www.cidersoftware.com
=============================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.