Re: Autorelease question
Re: Autorelease question
- Subject: Re: Autorelease question
- From: Dmitry Markman <email@hidden>
- Date: Thu, 3 Apr 2008 22:25:46 -0400
why do you think I didn't read all of that documentation?
I did
but, alas, maybe I'm not smart enough and I
can't tell which object is autoreleased and which one not
that was in principle my initial question
looking at the retainCount property won't tell you about was
object autoreleased or not
documentation doesn't tell
I posted my code you can see all 6 creation calls
how can you explain that
NSString *nsFontName = [NSString stringWithCString:fontName
encoding:NSMacOSRomanStringEncoding];
can be released, but
NSString *textString = [NSString stringWithCString:"Hello
From Cocoa" encoding:NSMacOSRomanStringEncoding];
can not
so what's the difference?
thanks
On Apr 3, 2008, at 10:10 PM, Rob Keniger wrote:
On 04/04/2008, at 11:54 AM, Dmitry Markman wrote:
if I comment all those releases (excerpt [pool release])
then application won't crash
That's because all the methods you use to create the objects return
autoreleased objects which don't need to be released manually.
that probably means that some of the objects
(stringAttributes, font, cocoaColor, context, textString or
nsFontName)
were already in the pool and I shouldn't release them
also if I call retain for every above object and call release the
everything will be fine with [pool release]
but why should I retain them if I have no intention to share them?
Listen to what Chris says:
You're releasing things you shouldn't be. Take some time to read
the memory management documentation.
Read Apple's memory management documentation as well as the many,
many articles about Objective-C memory management on the web. Read
"Programming in Objective-C" by Stephen Kochan.
You are doing it wrong, that's why it's crashing.
--
Rob Keniger
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
Dmitry Markman
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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