开发者

How to calculate memory usage of an object?

I'm implementing a caching system for android app, I need to add a parameter that specify the maximun amoun开发者_JAVA技巧t of memory permited for caching, but I don't know how to calculate the memory used for an object.


Apparently 1.5 added an instrumentation interface. Check out this article

http://www.javapractices.com/topic/TopicAction.do?Id=83

you can use a getObjectSize() method. Its implementation specific and an approximation but better than nothing


You can consider getting a heap dump of the application and observing its Retained Heap


It depends on the object. Calculate how much memory each part of the object takes when allocated to get a baseline for the max size the object can be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜