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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:02:18+00:00 2026-05-16T07:02:18+00:00

This might be pretty basic, but was very curious to know. Here’s the code

  • 0

This might be pretty basic, but was very curious to know.
Here’s the code snippet and the output

public class PlainSystemGC {

    public static void main(String ...strings) {

        System.out.println("Free Memory (Before GC): " + Runtime.getRuntime().freeMemory());

        System.gc();

        System.out.println("Free Memory (After GC): " + Runtime.getRuntime().freeMemory());
    }
}

and the output

Free Memory (Before GC): 1859640
Free Memory (After GC): 1911768

I am interested to know what is GC collecting here since no objects are created.

What’s the memory thats being freed up ? ( and that too 52kb )


@JSauer – It gives Exactly the same results even if run 100 times

  • 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-16T07:02:18+00:00Added an answer on May 16, 2026 at 7:02 am

    On most JVM implementations the main method is not actually the first piece of Java code that is run during the JVM startup.

    Usually, many parts of a complete JRE are themselves implemented in Java. For example a big part of the classloader mechanism is implemented in pure Java. It might even be able to write parts of the garbage collection algorithm itself in Java.

    Due to this, there may already be some garbage from those system classes that the gc can collect even if your application created no garbage at all.

    By the way, your application creates at least one object that is eligible for garbage collection at the point where System.gc() is called: The String that mentions the free memory is constructed dynamically and not held in a variable, so it could well be gc-ed during the System.gc() call.

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

Sidebar

Related Questions

This might be a very basic question but it confuses me. Can two different
okay this might be a pretty lame and basic question but its stuck in
I know this is a pretty basic question, but I don't know how to
This might be a pretty basic question, but how do you add new users
This might seem like a very easy question for some of you folks, but
This might sound like a stupid question but just trying to learn something here.
This might be a pretty basic question, or peculiar to my set up (hopefully
I know this question might be repeated many times but would really appreciate any
I have created a custom even class which is pretty basic. But when calling
This seems like a pretty basic thing to do but although I've been using

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.