• 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: Seemingly ridiculous problem...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seemingly ridiculous problem...


  • Subject: Re: Seemingly ridiculous problem...
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 14 Feb 2002 13:48:56 +0100

Sam,

>>>>>> Sam Goldman (SG) wrote at Thu, 14 Feb 2002 01:13:09 -0800:
SG> Some methods return autoreleased objects. Actually most do, but alloc,
SG> new, and I know there's another one that I am forgetting.

Actually, by convention, *ALL* do (*) but copy, mutableCopy, alloc, and
new... (whenever it is used, which should be sparingly, at least in
Foundation/AppKit).

As for a proper memory management, the method should look rather like this

-(id)function {
NSImage* pointer = [[[NSImage alloc]
initByReferencingFile:@"filename.jpg"] autorelease];
...
return someAutoreleasedOrSharedObject; // return pointer; would be all right
}

(*) return either autoreleased or shared object. The complete rule is:
whatever any method (but alloc/copy/mutableCopy/new...) returned is good for
the scope and ONLY for the scope. If you don't want to use it later (as using
of automatic variable indicates), just use it and forget it. If you do want
to use it later (than in the scope), you have to retain it.

Note that the above rule applies *either* in case of autoreleased object,
*or* in case of shared ones, which, of course, are *not* autoreleased.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Seemingly ridiculous problem... (From: Nick Müller <email@hidden>)

  • Prev by Date: Re: about help
  • Next by Date: Re: ObjC error messages
  • Previous by thread: Re: Seemingly ridiculous problem...
  • Next by thread: Re: Seemingly ridiculous problem...
  • Index(es):
    • Date
    • Thread