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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to