What is a `WeakReference` in Java and when should it be used?

Java Associate Hard

Java Associate — Hard

What is a `WeakReference` in Java and when should it be used?

Key points

  • `WeakReference` does not prevent garbage collection
  • Allows JVM to reclaim object when only weak references exist
  • Useful for scenarios where you want a reference without preventing collection

Ready to go further?

Related questions