• 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
Adding an observer is memory expensive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adding an observer is memory expensive


  • Subject: Adding an observer is memory expensive
  • From: Torsten Radtke <email@hidden>
  • Date: Thu, 10 Sep 2009 17:31:19 +0200

Hi,

I observed excessive memory usage (working in a garbage-collected environment under 10.6) if I add an observer to a KVO-compliant object. So if I add an observer to say 100000 objects, Instruments shows that 100000 2KB blocks of memory are allocated (additionaly there are another 100000 48B blocks and 200000 32B blocks). The stack trace for the 2KB blocks looks like this:

[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:]
[NSObject(NSKeyValueObserverRegistration) _addObserver:forProperty:options:context:]
NSKeyValueReplaceObservationInfoForObject
Auto::Zone::set_associative_ref(void*, void*, void*)
std::vector<__gnu_cxx::_Hashtable_node<std::pair<void* const, void*> >*, Auto::AuxAllocator<__gnu_cxx::_Hashtable_node<std::pair<void* const, void*> >*> >::reserve(unsigned long)


If I overwrite the observationInfo and setObservationInfo: methods and add an instance variable to the observed object, everything is fine. I filed this under rdar://7212101, but would like to know the opinion of this list, too.

Additionaly, if I remove the observer only 100000 32B blocks are released and collected. This also does not seem right to me.

Thanks,
Torsten
_______________________________________________

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


  • Prev by Date: Re: Table cell: how show blue when tapped only while editing is true?
  • Next by Date: Re: UIImagePickerController problem
  • Previous by thread: Re: UIImagePickerController problem
  • Next by thread: Re: Adding an observer is memory expensive
  • Index(es):
    • Date
    • Thread