Re: autoreleasing NSBezierPath object
Re: autoreleasing NSBezierPath object
- Subject: Re: autoreleasing NSBezierPath object
- From: Brendan Younger <email@hidden>
- Date: Wed, 27 Jun 2001 14:03:43 -0500
First of all, get far, far away from that book. From what I hear it's
more a hindrance than help.
Second, you hit the nail on the head with: "Or is it that the
NSBezierPath object is autoreleased by default, and if you really want
it, you need to retain it?" For future reference, your question is
about "convenience constructors." Any time you create an object without
explicitly using -alloc -allocWithZone -copy, etc. the object returned
to you is autoreleased already. For instance, this is what the code for
-bezierPathWithOvalInRect: might look like:
+ (id)bezierPathWithOvalInRect:(id)rect
{
self = [[NSBezierPath alloc] initWithRect:rect];
return [self autorelease];
}
Therefore, [[[NSBezierPath bezierPathWithOvalInRect:dotRect]
autorelease] fill]; will crash because the object will be autoreleased
twice and this does bad things to memory.
Stepwise has a great article about this, check out
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html.
Brendan Younger