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

1
  • What size object are you using? Have you considered using Core Data to put the unused portions of that object to disk? Commented Mar 14, 2011 at 15:22

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Awesome, thanks! It's always the basic C-functions I can't find in the documentation. Really must get some better reference documents.
See here for how to get estimated total memory use of your process, perhaps related to motivation for your question: stackoverflow.com/questions/787160/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.