Java中ArrayList的内存大小是多少 [英] What is the memory size of an ArrayList in Java

查看:690
本文介绍了Java中ArrayList的内存大小是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ArrayList< Obj> ,我想知道它使用了多少内存。

I have an ArrayList<Obj> and I wish to know how much memory it is using.

Obj 是变体,所以它并不像根据对象的大小乘以数组中的元素数一样容易。

The Obj is variant so, it is not as easy as multiply the number of elements in the array per the size of an object.

推荐答案

您可以使用 Runtime.getRuntime()。totalMemory() 及其对应 Runtime.getRuntime()。freeMemory() 获得有根据的猜测,但这并不能解释在通话之间使用GC的对象。

You can use something like Runtime.getRuntime().totalMemory() and its counterpart Runtime.getRuntime().freeMemory() to get an educated guess, but that doesn't account for objects that are GC'ed between calls.

这篇关于Java中ArrayList的内存大小是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆