• 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: alloc, init and autorelease/release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alloc, init and autorelease/release


  • Subject: Re: alloc, init and autorelease/release
  • From: jkp <email@hidden>
  • Date: Sun, 23 Oct 2005 11:47:35 +0100

I think he is trying to work out if you can do clever things in your init methods like return an existing instance for example (like with a singleton class, or some caching scheme). The examples he gave show ways you might attempt to do this.

The answer is yes, releasing the object passed to init is fine, you can return something else or nil if needed. joar is right about autorelease there tho, no point whatsoever.

jkp

On 22 Oct 2005, at 17:35, j o a r wrote:


On 22 okt 2005, at 15.32, Felix Schwarz wrote:


Code sample 1:


Valid. I would have used release, and not autorelease, but it's not very important. It just seems pointless to use autorelease there.



Code sample 2:


Invalid, unless you call [super init] in "-someOtherInit:", in which case it's OK.
Same thing about release vs. autorelease applies here too.



Or, in other words, is it ok to autorelease and or release an object right after "alloc"ation, before it was "init"ialized?


Yes, I guess it is, but I wouldn't do:


I.e. is it ok to do

    id someObj = [SomeObj alloc];
    [someObj release];

or

    id someObj = [SomeObj alloc];
    [someObj autorelease];


Simply because it breaks the rule that you should always alloc+init on the same row.
I also don't really see when you would want to do the above?


j o a r


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40kirkconsulting.co.uk


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: alloc, init and autorelease/release
      • From: Felix Schwarz <email@hidden>
References: 
 >alloc, init and autorelease/release (From: Felix Schwarz <email@hidden>)
 >Re: alloc, init and autorelease/release (From: j o a r <email@hidden>)

  • Prev by Date: Re: FSRefMakePath: error -35
  • Next by Date: Re: Cocoa UI in carbon plug-in?
  • Previous by thread: Re: alloc, init and autorelease/release
  • Next by thread: Re: alloc, init and autorelease/release
  • Index(es):
    • Date
    • Thread