• 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: GC Basic questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC Basic questions


  • Subject: Re: GC Basic questions
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 19 Oct 2009 23:54:58 -0700

On Oct 19, 2009, at 23:35, Nick Rogers wrote:

Since the methods -release, -retain and -autorelease are no-ops with GC only enabled, How do I release everything associated with an ivar (pointer to a class) in AppController?
Currently I'm doing it by setting this pointer as nil. Is it ok?


Also when I follow certain steps, this pointer gets a lot of memory attached, down the line. which gets released (when I set it to nil) as per Obj-Alloc instrument.
But when following another certain steps, this memory doesn't get released (when setting this pointer nil), why? With GC only enabled this should get freed up.

You should read -- several times probably -- the documentation on the garbage collector:


	http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/GarbageCollection/Introduction.html

That will tell you that you don't have to do anything to 'release' memory under GC -- memory is collected when there are no "live" references to it. So if your pointer is *the* reference that's keeping the memory alive (along with everything indirectly pointed to), then yes setting the pointer to nil should result in the whole shebang be collected -- at some later time that you don't directly control.

OTOH, if the ivar is in an instance which is itself unreferenced, setting the ivar to nil is unnecessary because it's no longer a live reference. A typical usage scenario of this is when the pointer to the instance is in a local (stack) variable of a method, and you return from the method. There's no need to nil anything in that case, because the return ends the lifetime of the instance, which the ends the lifetime of the object pointed to by the ivar, which ends ... etc.


_______________________________________________

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


References: 
 >GC Basic questions (From: Nick Rogers <email@hidden>)

  • Prev by Date: Re: CPU utilization in Snow Leopard
  • Next by Date: Re: GC Basic questions
  • Previous by thread: GC Basic questions
  • Next by thread: Re: GC Basic questions
  • Index(es):
    • Date
    • Thread