The situation is a bit complex. I have a web container which controls another app in another machine using RMI. RMI server side has a HashMap which contains user information that the web app side needs to control.
When user logs out from web app side, there will be an RMI call to RMI server, telling the server to logout user. Then I just remove the item in the HashMap.
Now I realize the GC will not collect the object I removed in HashMap because maybe other thread is still using it and the object also contains some subobjects such as user contacts.
I really have no idea how to destroy the whole object including its properties and properties' properties.
Well, you have to remove all hard references to your object to make it eligible for garbage collection. There's no other way out. What is the other thread in your case?
If this is a case of Distributed Garbage Collection (i.e. the client has a remote reference to an object which exists on the server), this system works by having the server keep track of which clients have requested access to remote objects running on the server. When a reference is made, the server marks the object as "dirty" and when a client drops the reference, it is marked as being "clean".
In these cases, if the client doesn't regularly notify the server that the objects are still in use, the server should automatically garbage collect them after a period of time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With