• 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: KVO leaks memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO leaks memory


  • Subject: Re: KVO leaks memory
  • From: Greg Parker <email@hidden>
  • Date: Fri, 24 Apr 2009 17:48:54 -0700

On Apr 24, 2009, at 5:09 PM, Andreas Grosam wrote:
model creates several other objects that will be stored in a dictionary which is also an ivar of model. The dictionary will be used as a parameter in a recursive method invocation, where its sub dictionaries will be processed. Well, and it seemed practically to me (probably after a 14 hours day) to insert references to model to some sub-dictionaries at some point of the process. Unluckily, inserting an object increases its retain count, so the model retained itself through the dictionary - and could never be dealloced ;)
So, once I found the error, I could fix it in 5 seconds.


Just curious, if GC would solve this kind of self-referencing issue.

Short answer: yes.

Any garbage collector worth the name will reclaim cycles of objects that point to each other, as long as none of them are referenced by any "really" live object. If there is no chain to the objects from global variables or the stack, then they'll die eventually.

Longer answer: yes, unless you build a trap using CFRetain or - [NSGarbageCollector disableCollectorForPointer].

Objective-C's garbage collector adds one more complication. Retain counts from CFRetain() still work: a CFRetained object will not be deleted. You can get into trouble if you have a cycle of objects, and one of them is CFRetained, and the balancing CFRelease() is in the finalizer of another object in the cycle. The finalizer won't get called because the object is referenced by a CFRetained object, and the CFRetained object won't get CFReleased because that other finalizer isn't called.


-- Greg Parker email@hidden Runtime Wrangler


_______________________________________________

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: 
 >KVO leaks memory (From: Andreas Grosam <email@hidden>)
 >Re: KVO leaks memory (From: Jean-Daniel Dupas <email@hidden>)
 >Re: KVO leaks memory (From: Andreas Grosam <email@hidden>)

  • Prev by Date: Re: Core Data and the Application Delegate
  • Next by Date: Re: Core Data and the Application Delegate
  • Previous by thread: Re: KVO leaks memory
  • Next by thread: Fill box with repeating text
  • Index(es):
    • Date
    • Thread