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 9198785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:22:10+00:00 2026-06-17T22:22:10+00:00

Possible Duplicate: Garbage Collection and Threads I got this question in an interview: Assuming

  • 0

Possible Duplicate:
Garbage Collection and Threads

I got this question in an interview:
Assuming we have multiple threads created, if one of the threads calls garbage collection, will the un-referenced objects in other threads be collected also?

  • 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-06-17T22:22:11+00:00Added an answer on June 17, 2026 at 10:22 pm

    Yes and no.

    if one of the threads calls garbage collection, will the un-referenced objects in other threads be collected also?

    Yes. Objects are not "in threads" — there is a single object graph for all threads running in the program, so when GC happens, unreachable objects are collected regardless of which thread created them, or had local references to them.

    No. When a thread calls Runtime.gc() the VM is not obliged to actually do anything so it may be that no GC happens and no memory is collected. For example it has no effect when -XX:+DisableExplicitGC is specified at the command line.

    Runtime.gc()

    Calling this method suggests that the Java virtual machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse.

    No. Even when a GC happens, not all unreachable objects that were only ever reachable from one thread’s stack will necessarily be collected since generational GCs only deal with a subset of the object graph, and if that subset happens to contain all the unreachable objects created by a particular thread then it is only coincidence.

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

Sidebar

Related Questions

Possible Duplicate: How to implement garbage collection in C++ I was recently asked this
Possible Duplicate: Java garbage collection I know that we have to free object in
Possible Duplicate: Do event handlers stop garbage collection from occuring? I had one wp7
Possible Duplicate: difference between destructor and garbage collector Recently i asked this question ,
Possible Duplicate: Garbage Collection in C++ — why? Hi, I read few articles about
Possible Duplicate: Is there garbage collection in PHP? In java there is a concept
Possible Duplicate: Forcing Garbage Collection in Java? Can I Force Garbage Collection in Java
Possible Duplicate: What is the garbage collector in Java? Within my program, I have
Possible Duplicate: Garbage collection behaviour for String.intern() How does Java store Strings and how
Possible Duplicate: .NET garbage collection not working properly here? I've tested the following code.

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.