clearing or set null to objects in java

前端 未结 7 1670
盖世英雄少女心
盖世英雄少女心 2020-12-09 09:18

I was recently looking into freeing up memory occupied by Java objects. While doing that I got confused about how objects are copied (shallow/deep) in Java and how to avoid

7条回答
  •  醉话见心
    2020-12-09 09:51

    To clear the variable

    According to my knowledge,

    If you are going to reuse the variable, then use

                   Object.clear();
    

    If you are not going to reuse, then define

                   Object=null;
    

    Note: Compare to removeAll(), clear() is faster.

    Please correct me, If I am wrong....

提交回复
热议问题