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?