How to use PhantomReference as finalize() Replacement
Javadoc 8 for PhantomReference states: Phantom references are most often used for scheduling pre-mortem cleanup actions in a more flexible way than is possible with the Java finalization mechanism. So I tried creating a thread that is calling the close() method of a Test Object that is eligible for garbage collection. The run() tries to get all Test Objects pre-mortem . Actually the retrieved Test Objects are all null . The expected behavior is, that the Test Objects are retrieved and the close method is called. No matter how many Test Objects you create there is not a single Test Object that