Re: Autorelease question
Re: Autorelease question
- Subject: Re: Autorelease question
- From: Dmitry Markman <email@hidden>
- Date: Thu, 3 Apr 2008 22:18:48 -0400
On Apr 3, 2008, at 9:52 PM, Chris Suter wrote:
You're releasing things you shouldn't be. Take some time to read the
memory management documentation.
well, exactly
so here is what I have
NSString *nsFontName = [NSString stringWithCString:fontName
encoding:NSMacOSRomanStringEncoding];
NSString *textString = [NSString stringWithCString:"Hello
From Cocoa" encoding:NSMacOSRomanStringEncoding];
NSGraphicsContext *context = [NSGraphicsContext
graphicsContextWithGraphicsPort:cgContext flipped:TRUE];
NSColor *cocoaColor = [NSColor colorWithCalibratedRed:r
green:g blue:b alpha:alpha];
NSFont *font = [NSFont fontWithName:nsFontName size:fontSize];
NSMutableDictionary *stringAttributes = [NSMutableDictionary
dictionaryWithCapacity:4];
documentation for
+[NSString
stringWithCString:encoding
] no word about
releasing / retaining
+[NSGraphicsContext graphicsContextWithGraphicsPort: flipped:]
it says "Return Value: The created NSGraphicsContext object or nil
if the object could not be created."
so I suppose I should release it
+[NSColor colorWithCalibratedRed:green:blue:alpha]; no word about
releasing / retaining
it says: "Return Value The color object." so I suppose I should
release it, because it returns new object
+[NSFont fontWithName: size:fontSize];
from documenattion
"Return Value
A font object for the specified name and size.
Discussion
The fontName is a fully specified family-face name, such as Helvetica-
BoldOblique or Times-Roman. The fontSize is equivalent to using a font
matrix of [fontSize 0 0 fontSize 0 0] withfontWithDescriptor:size:. If
you use a fontSize of 0.0, this method uses the default User Font size.
Fonts created with this method automatically flip themselves in
flipped views. This method is the preferred means for creating fonts."
so it said "created" so I thought I should release it
and finally
+[NSMutableDictionary dictionaryWithCapacity]
Return Value
A new mutable dictionary with enough allocated memory to hold numItems
entries.
it says "NEW" so I suppose I should release it
I just thought that all those 5 methods are CREATION methods they are
not GET methods
so how do I know which one I should release?
after playing with those releases I found that only
[font release];
[nsFontName release];
are harmless
it looks like that they were cached
it doesn't make any sense to me (at least yet :-( )
it looks like that solution is to go to GarbageCollection and forget
about
pools/release e.t.c
that's what Apple wants? :-))
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