什么是Java中的ArrayList的内存大小 [英] What is the memory size of a ArrayList in Java

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

问题描述

我有一个ArrayList和我想知道它是使用多少内存。

I have a ArrayList 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 a object

感谢。

推荐答案

您可以使用类似的 调用Runtime.getRuntime()。totalMemory() 以及其对应的 调用Runtime.getRuntime ().freeMemory() 让一个受过教育的猜测,但这并不占被调用之间GC'ed对象。

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天全站免登陆