Re: iPhone resource cache - memory question
Re: iPhone resource cache - memory question
- Subject: Re: iPhone resource cache - memory question
- From: Jens Alfke <email@hidden>
- Date: Thu, 6 May 2010 11:04:50 -0700
On May 6, 2010, at 10:13 AM, Philip Mobley wrote:
I am trying to implement a generic resource management singleton
class that will load all of the images, sounds, and data files for
the app. This resource manager will keep track of how frequently
each object is requested (or in the case of sounds when they are
played). Then when an applicationDidReceiveMemoryWarning: message
was received, the manager would purge from memory the less
frequently used items (but ready to load them again if they are
requested).
This sounds like a fine idea. I'm not sure why Shripada thought it was
incorrect.
Thats why I was wondering if there was a generic approach to get
either the total app memory used, or get total memory used by a
particular object (recursively following pointers of course).
I don't know of an API to get the total heap size. There are system
calls to find out about address space usage, but that's not the same
thing, as lots of other stuff gets mapped into your process's address
space, like shared libraries and mapped files.
Memory usage of an object is a fuzzy concept. You can follow pointers
in your own custom objects, but you'll likely reach objects that are
used by multiple instances, and do you count those once or many times?
And what about cycles? (In other words, your object graph is almost
never a tree; it's usually at least a DAG and most often cyclic.)
There's no reliable way to follow pointers in objects whose classes
you don't own, because the instance variables of those are private.
(Yes, there are ways you could do this by looking at the framework
headers, but in the case of system classes you'll find that many of
them have an instance variable like "void *_private_data" that points
to a struct that has no public declaration. Good luck following that.)
—Jens_______________________________________________
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