What is a phantom reference in Java and when is it used?

Java Professional Hard

Java Professional — Hard

What is a phantom reference in Java and when is it used?

Key points

  • Phantom references are enqueued in a ReferenceQueue after finalization
  • They enable cleanup actions without resurrecting the object
  • They are different from null references or weak references
  • Phantom references are often used for resource cleanup after object finalization

Ready to go further?

Related questions