分配“空”在每个应用程序中使用后的对象 [英] Assigning "null" to objects in every application after their use

查看:116
本文介绍了分配“空”在每个应用程序中使用后的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 在到达范围之后,您是否一直将 null 分配给对象?


  • 还是你依靠JVM进行垃圾回收?


  • 您是否为所有类型的应用程序都这样做?如果是,是否总是一个好的做法?



解决方案

b

  • 否,不要这样做,除非特定情况(例如静态字段)或您知道变量/字段的生命周期很多

  • 是的,但具有对您的VM限制的工作知识(以及如何导致意外阻止内存块)



    • Do you always assign null to an object after its scope has been reached?

    • Or do you rely on the JVM for garbage collection?

    • Do you do it for all sort of applications regardless of their length?

    • If so, is it always a good practice?

    解决方案

    • no, don't do that, except for specific cases such as static fields or when you know a variable/field lives a lot longer than the code referencing it
    • yes, but with a working knowledge of your VM's limits (and how to cause blocks of memory to be held accidentally)
    • n/a

    这篇关于分配“空”在每个应用程序中使用后的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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