java中的内存使用情况 [英] Memory usage in java

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

问题描述

如果一个对象的大小是110个字节并且有1000个这样的对象,那么我们如何有效地调用使用该对象的方法,以便需要最少的内存。?



我尝试了什么:



我尝试过循环来创建对象,然后调用方法。但我想减少所需的内存。在我的情况下,我认为有更大的内存头,因为java是通过值传递。所以调用1000次会占用多少内存?

If the size of one object is 110 bytes and there are 1000 such objects then how can we efficiently call a method using this object so that minimum memory is required.?

What I have tried:

I have tried loop for creating the objects and then call the method. But i want to reduce the memory required.In my case I think there is greater memory head because java is pass by value. So calling 1000 times will take how much of memory?

推荐答案

如果你需要创建 1000 对象那么你需要这样的 1000 对象所需的内存,这是直接来自Captain Obvious的明智之举。



另一方面,您不需要担心将对象传递给方法所需的内存量。 Java 按值传递参数;但是在对象的情况下,有值引用传递的值。
If you need to create 1000 objects then you need the memory required for such 1000 objects, that's a wise truth directly coming from Captain Obvious.

On the other hand, you don't need to be worried by the amount of memory required to pass object to methods. Java passes arguments by value right enough; but in case of objects, there are object references passed by value.


这篇关于java中的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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