Java:将Array设置为null以释放内存 [英] Java: Setting Array to null to free memory

查看:270
本文介绍了Java:将Array设置为null以释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,在其中分配大数组,将它们填满,然后将它们放入缓冲区.完成此操作后,阵列将摆在周围,无所事事.理论上将它们设置为null会提高我的应用程序的性能,还是效果可以忽略/不存在?

I have an Android application where I allocate large arrays, fill them up, and throw them into buffers. After doing this, the arrays are lying around, doing nothing. Would setting them to null theoretically improve the performance of my app, or is the effect negligible/nonexistent?

推荐答案

通常不,将数组设置为null不会以任何方式提高性能或内存使用率.

Generally no, setting the array to null will not improve performance or memory use in any way.

当垃圾收集器确定该对象不再可访问时,它将释放内存.显式地将引用设置为null可以很好地向垃圾回收器发出信号,表明该对象是可释放的,但是如果这些数组已经不再被引用(例如,不再包含其包含的对象),则可以对其进行显式设置设置为null不会使垃圾收集更快地发生.

The garbage collector will free up the memory when it decides that the object is no longer accessible. Explicitly setting a reference to null is a good signal to the garbage collector that the object is free-able, but if those arrays are already no longer being referenced anyway (because, say, their containing object is no longer referenced) then explicitly setting it to null won't make the garbage collection happen any more quickly.

这篇关于Java:将Array设置为null以释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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