How to destroy java objects?

后端 未结 5 1514
误落风尘
误落风尘 2020-12-06 07:43

Well, I have developed a java application using several objects relationships that make the memory usage too expensive. I have no experience managing the java memory because

5条回答
  •  一个人的身影
    2020-12-06 08:10

    What you could do is make one intermediate class. For example, if you have instance of class A, for which you have a lot of references and you want to remove it but a lot of references makes it difficult, you can do the following: create instance of class B that contains nothing other than reference to instance of class A (like some kind of proxy). Now you will have a lot of references to instance of class B but just one reference to instance of class A, which you can easily remove and garbage collector will collect instance of class A.

    Image shows difference when using proxy (instance of class B): Now only one reference has to be removed.

    enter image description here

提交回复
热议问题