Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 799503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:08:17+00:00 2026-05-14T23:08:17+00:00

Effective Java says: A third common source of memory leaks is listeners and other

  • 0

Effective Java says:

A third common source of memory leaks
is listeners and other callbacks. If
you implement an API where clients
register callbacks but don’t
deregister them explicitly, they will
accumulate unless you take some
action. The best way to ensure that
callbacks are garbage collected
promptly is to store only weak
references to them, for instance, by
storing them only as keys in a
WeakHashMap.

I am a beginner in Java. Could somebody teach me how to create weak references in callbacks and tell me how they solve the memory leak problems? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:08:18+00:00Added an answer on May 14, 2026 at 11:08 pm

    Read this article

    The key take aways are :

    You can think of direct references as
    strong references that require no
    extra coding to create or access the
    object. The remaining three types of
    references are subclasses of the
    Reference class found in the
    java.lang.ref package. Soft references
    are provided by the SoftReference
    class, weak references by the
    WeakReference class, and phantom
    references by PhantomReference.

    Soft references act like a data cache.
    When system memory is low, the garbage
    collector can arbitrarily free an
    object whose only reference is a soft
    reference. In other words, if there
    are no strong references to an object,
    that object is a candidate for
    release. The garbage collector is
    required to release any soft
    references before throwing an
    OutOfMemoryException.

    Weak references are weaker than soft
    references. If the only references to
    an object are weak references, the
    garbage collector can reclaim the
    memory used by an object at any time.
    There is no requirement for a low
    memory situation. Typically, memory
    used by the object is reclaimed in the
    next pass of the garbage collector.

    Phantom references relate to cleanup
    tasks. They offer a notification
    immediately before the garbage
    collector performs the finalization
    process and frees an object. Consider
    it a way to do cleanup tasks within an
    object.

    followed by the WeakListModel listing which I won’t post to avoid cluttering this response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Effective Java says that readResolve works only if all fields are transient .
Effective java says: // Potential security hole! static public final Thing[] VALUES = {
Effective Java says : There is a severe performance penalty for using finalizers. Why
Item 16 of Effective Java 2nd edition, favor composition over inheritance says the following
Effective Java , along with other sources suggest that we should consider using composition
The book Effective Java and other sources provide a pretty good explanation on how
I am reading about clone from Effective Java It says that in clone the
In the book Effective Java, Josh Bloch says that StringBuffer is largely obsolete and
I am reading Effective Java . In the discussion about finalize, he says C++
Effective Java (Joshua Bloch) Item 17 says : Design and Document or inheritance or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.