Ensuring Destruction of a Java Object
The situation is a little tricky. I have a web container that manages another application on a different machine using RMI. On the RMI server side, there is a HashMap that contains user information that the web application side must control.
When the user logs out from the web application side, the RMI server will be invoked on the RMI server, telling the server to log off. Then I just remove the item in the HashMap.
Now I understand that the GC will not collect the object I deleted in the HashMap because maybe another thread is still using it and the object also contains some sub-objects like custom pins.
I don't really know how to destroy the entire object, including its properties and properties.
source to share
Well, you need to remove all hard links to your object to make it garbage collection. There is no other way out. What's the other thread in your case?
source to share
If this is the case with distributed garbage collection (that is, the client has a remote reference to an object that exists on the server), this system works if the server keeps track of which clients have requested access to remote objects running on the server. When a link is made, the server marks the object as dirty, and when the client drops the link, it marks it as clean.
In these cases, if the client does not regularly inform the server that the objects are still in use, the server should automatically garbage collect them after a certain period of time.
source to share