• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Autorelease question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Autorelease question
      • From: "Sherm Pendley" <email@hidden>
    • Re: Autorelease question
      • From: Dave Hersey <email@hidden>
    • Re: Autorelease question
      • From: "stephen joseph butler" <email@hidden>
References: 
 >Autorelease question (From: Dmitry Markman <email@hidden>)
 >Re: Autorelease question (From: Robert Claeson <email@hidden>)
 >Re: Autorelease question (From: Jens Alfke <email@hidden>)
 >Re: Autorelease question (From: Dmitry Markman <email@hidden>)
 >Re: Autorelease question (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: Autorelease question
  • Next by Date: Re: Autorelease question
  • Previous by thread: Re: Autorelease question
  • Next by thread: Re: Autorelease question
  • Index(es):
    • Date
    • Thread