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

  • SEARCH
  • Home
  • 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 6536615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:30:53+00:00 2026-05-25T10:30:53+00:00

I was reading this due to some memory issues I was having in my

  • 0

I was reading this due to some memory issues I was having in my code relating to weak references, when I came across this little note:

You have to explicitly set that strong reference to null after use:

This one isn’t so obvious: you might think that a strong reference ceases to exist once it goes out of scope. However, the JVM isn’t required to do so, and for efficiency’s sake, won’t. The strong reference remains in the stack frame, and can get in the way of garbage collection.

Is this still true? If I do something like:

void foo(){
    Object obj = weakRef.get();
    doStuffWith(obj);
}

Is it required that I set obj = null when I’m done with the method, or else I’ll leak obj?

  • 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-25T10:30:55+00:00Added an answer on May 25, 2026 at 10:30 am

    It is true that JVM isn’t required to do so. As a matter of fact, JVM isn’t required to do GC at all.

    But a JVM that doesn’t nullify a local reference is as unreasonable as a JVM that doesn’t do GC.

    (Well, there are people who give gigantic memory to JVM, and turn off GC completely; they simply restart the app every N days.)

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

Sidebar

Related Questions

Reading this question I found this as (note the quotation marks) code to solve
I was recently reading a question here (some time this week), which I can't
Recently, I am reading some Linux kernel space codes, I see this uint64_t used;
This question is a bit long due the source code, which I tried to
I am trying to work out some memory leak issues in an application, and
After reading this post and some derivative publications (ddotdash.com) I wonder whether it is
I'm writing some code for a statistics package, and I start off by reading
Reading this post has left me wondering; are nightly builds ever better for a
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
After reading this question , I was reminded of when I was taught Java

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.