Home > Back-end >  The destruction of objects
The destruction of objects

Time:04-21

In Java, if an object inside a member variable is an object, the object is not pointing to will be destroyed? The inside of the member variable object will be destroyed?

CodePudding user response:

To see whether the object of the management way,
1. If the object is a container managed, so will be destroyed;
2. If it is spring management object, then according to the management of the object to see spring factory (create and destroy), the singleton and multiple meeting is different, the release of the JVM, depends on the destruction of the spring factory,

CodePudding user response:

This problem involves the Java garbage collection mechanism about how to recognize no reference object, in the knowledge points a lot of online tutorials, to search for
In general, garbage collector will be from the root node object (global and static variables, this is often come into contact with, and other types of the root node) to search the object reference, can be analyzed step by step out a reference tree
Beyond the tree will be destroyed
So you say this kind of circumstance is A - & gt; B, A reference, A, will be destroyed. But if you quote, B is C B will not be destroyed; Unless B only be A reference

All of the spring bean's stored in a static map, so in forever
  • Related