1

I'm trying to find a way of limiting the amount of memory a particular custom object is using, based on how much memory is left. The most useful way of doing this would be some kind of method or function that checks to see how much memory a given C Object is using. This way the program can reject the creation of further data when the object reaches its preset limit, rather than going ahead and creating it then dealing with the memory warning in retrospect.

Does anyone know of Cocoa methods that: A) Return how much memory is being used by a given object B) Return how much more memory the system can use up before it generates a warning

-Ash

Ash
  • 9,064
  • 3
  • 48
  • 59

1 Answers1

4

A. You can get size of an object using malloc_size(myObject) (you need to traverse all the nested objects too). Also check docs for NSCache.

B. No, there is no documented way to do that

Max
  • 16,679
  • 4
  • 44
  • 57
  • Awesome, thanks! It's always the basic C-functions I can't find in the documentation. Really must get some better reference documents. – Ash Mar 14 '11 at 17:22
  • 1
    See here for how to get estimated total memory use of your process, perhaps related to motivation for your question: http://stackoverflow.com/questions/787160/programmatically-retrieve-memory-usage-on-iphone – Colin Nov 04 '11 at 08:21