• 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: release and reference counting query
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: release and reference counting query


  • Subject: Re: release and reference counting query
  • From: Marc Stibane <email@hidden>
  • Date: Fri, 21 Nov 2008 20:15:32 +0100

Am 19.11.2008 um 10:05 schrieb mmalcolm crawford:

On Nov 18, 2008, at 10:33 AM, Marc Stibane wrote:
Lets forget for a moment that the dealloc never get's called at all on the iPhone
This is simply untrue.

Nope.
Try to set a breakpoint inside the dealloc in the same file as applicationDidFinishLaunching, run your app and press the home button.
Never called, and purposely so - the application finishes anyway, so why spend cycles deallocating small blocks one-by-one when you can just throw away all memory the app used in one block...



So why the local var?
3 lines of code instead of 1...
Isn't a main goal of Cocoa to write *less* code?

Because:
Cocoa strongly advocates you use accessor methods to set instance variables(*);
You are discouraged from setting instance variables directly anywhere other than in initializers and dealloc(*);

For me, applicationDidFinishLaunching IS an initializer...


On iPhone in particular, you should avoid the use of autorelease.
The latter point in particular means that this alternative:
self.viewController = [[[UIViewController alloc]
initWithNibName:@"MoveMeView" bundle:[NSBundle mainBundle]] autorelease];
does not follow best practice.
Thus -- almost by a process of elimination -- you're left with the pattern shown in iPhone samples.

I stick with my applicationDidFinishLaunching implementation - 1 line instead of 3.
Of cause you're right were it some other method which could be called more than once and not applicationDidFinishLaunching, which is only called once and - as stated above - never paired with dealloc (however, applicationWillTerminate is called).


--

In a world without walls and fences,
   who needs windows and gates?




_______________________________________________

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: release and reference counting query
      • From: mmalcolm crawford <email@hidden>
References: 
 >release and reference counting query (From: Calum Robertson <email@hidden>)
 >Re: release and reference counting query (From: Roland King <email@hidden>)
 >Re: release and reference counting query (From: Marc Stibane <email@hidden>)
 >Re: release and reference counting query (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: BOOL value in Dictionary
  • Next by Date: Re: release and reference counting query
  • Previous by thread: Re: release and reference counting query
  • Next by thread: Re: release and reference counting query
  • Index(es):
    • Date
    • Thread