Re: autoreleasing NSBezierPath object
Re: autoreleasing NSBezierPath object
- Subject: Re: autoreleasing NSBezierPath object
- From: Joe Muscara <email@hidden>
- Date: Wed, 27 Jun 2001 14:42:41 -0500
Hello Oscar Bascara, I'm Joe Muscara! ;~)
You ask a very good question. I would consider myself a Cocoa newbie as
well, so someone out there may do a better or more accurate job
explaining this.
What I think is happening is that the NSBezierPath object is being
autoreleased. You only need to worry about releasing/autoreleasing
objects that you instantiate. Or to quote mmalcolm crawford,
"Objects created using convenience constructors (e.g. NSString's
stringWithString) are considered autoreleased."
<
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html>
You should check out this article and the other ones on Stepwise that he
references, and you should read them again, and again, and again... :~)
I think the way it works is that if you instantiate an object with an
"alloc..." method, you need to release it. If the object is created via
a built-in class method (or rather, "convenience constructor," and these
usually seem to be named something like "classNameWith..." but are they
always?) then it is considered autoreleased.
HTH
Joe
On Wednesday, June 27, 2001, at 12:36 PM, Oscar Bascara
<email@hidden> wrote:
Here's a newbie question.
In Learning Cocoa, the Dot View project calls the following line in the
drawRect: method:
[[NSBezierPath bezierPathWithOvalInRect:dotRect] fill];
Does the NSBezierPath object that gets created (allocated and
initialized) need to be autoreleased?
[[[NSBezierPath bezierPathWithOvalInRect:dotRect] autorelease] fill];
The object is never explicitly released/autoreleased in the program.
Since drawRect: can be called many times, I'm just concerned about a
possible memory leak.
Or is it that the NSBezierPath object is autoreleased by default, and if
you really want it, you need to retain it?