• 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: Files and arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Files and arrays


  • Subject: Re: Files and arrays
  • From: Ondra Cada <email@hidden>
  • Date: Sat, 16 Nov 2002 16:14:59 +0100

On Saturday, November 16, 2002, at 04:02 , Jim Balhoff wrote:

The buggy code is purely my own.

You won't get it patented anyway, for others did it before ;)

Well to cut the long story short, whenever you create an object to put it into an automatic variable (or into another object), ensure it is autoreleased (or shared):

{
id local=[AClass aClassWith...];
id local2=[[[AClass alloc] initWith...] autorelease];
...
[anArray addObject:[AClass aClassWith...]];
[anArray addObject:[[[AClass alloc] initWith...] autorelease]];
}

Only in case you store the object into a global or instance variable, you should use [[AClass alloc] initWith...], or the practically equivalent (unnoticeably less effective) [[AClass aClassWith...] retain].

(Of course there are exceptions to this rule, but they are just that -- exceptions, for cases where there is a hard reason to do it some other way.
)
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.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: Files and arrays (From: Jim Balhoff <email@hidden>)

  • Prev by Date: Re: Beginner questions
  • Next by Date: Re: Cocoa app within a browser window
  • Previous by thread: Re: Files and arrays
  • Next by thread: Testing...
  • Index(es):
    • Date
    • Thread