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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:39:09+00:00 2026-05-24T15:39:09+00:00

I have an application that causes an OutOfMemoryError, so I try to debug it

  • 0

I have an application that causes an OutOfMemoryError, so I try to debug it using Runtime.getRuntime().freeMemory(). Here is what I get:

freeMemory=48792216
 ## Reading real sentences file...map size=4709. freeMemory=57056656
 ## Reading full sentences file...map size=28360. freeMemory=42028760
freeMemory=42028760
 ## Reading suffix array files of main corpus ...array size=513762 freeMemory=90063112
 ## Reading reverse suffix array files... array size=513762. freeMemory=64449240

I try to understand the behaviour of freeMemory. It starts with 48 MB, then – after I read a large file – it jumps UP to 57 MB, then down again to 42 MB, then – after I read a very large file (513762 elements) it jumps UP to 90 MB, then down again to 64 MB.

What happens here? How can I make sense of these numbers?

  • 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-24T15:39:10+00:00Added an answer on May 24, 2026 at 3:39 pm

    Java memory is a bit tricky. Your program runs inside the JVM, the JVM runs inside the OS, the OS uses your computer resources. When your program needs memory, the JVM will see if it has already requested to the OS some memory that is currently unused, if there isn’t enough memory, the JVM will ask the OS and, if possible, obtain some memory.

    From time to time, the JVM will look around for memory that is not used anymore, and will free it. Depending on a (huge) number of factors, the JVM can also give that memory back to the OS, so that other programs can use it.

    This mean that, at any given moment, you have a certain quantity of memory the JVM has obtained from the OS, and a certain amount the JVM is currently using.

    At any given point, the JVM may refuse to acquire more memory, because it has been instructed to do so, or the OS may deny the JVM to access to more memory, either because again instructed to do so, or simply because there is no more free RAM.

    When you run your program on your computer, you are probably not giving any limit to the JVM, so you can use plenty of RAM. When running on google apps, there could be some limits imposed to the JVM by google operators, so that available memory may be less.

    Runtime.freeMemory will tell you how much of the RAM the JVM has obtained from the OS is currently free.

    When you allocate a big object, say one MB, the JVM may require more RAM to the OS, say 5 MB, resulting in freeMemory be 4 MB more than before, which is counterintuitive. Allocating another MB will probably shrink free memory as expected, but later the JVM could decide to release some memory to the OS, and freeMemory will shrink again with no apparent reason.

    Using totalMemory and maxMemory in combination with freeMemory you can have a better insight of your current RAM limits and consumption.

    To understand why you are consuming more RAM than you would expect, you should use a memory profiler. A simple but effective one is packaged with VisualVM, a tool usually already installed with the JDK. There you’ll be able to see what is using RAM in your program and why that memory cannot be reclaimed by the JVM.

    (Note, the memory system of the JVM is by far more complicated than this, but I hope that this simplification can help you understand more than a complete and complicated picture.)

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

Sidebar

Related Questions

I have a thread in a Java web application that causes a java.lang.OutOfMemoryError: Java
I have one form in a PHP (5.2.9-1) application that causes IIS (Microsoft-IIS/6.0) to
Using Netbeans 6.8 and metro 2.0 I have written a simple application that makes
We have an installer for application that is compiled using WiX and each version
I have an application that sometimes causes exceptions. And I need to restart it
I have an application that executes workflows using WorkflowApplication as well as doing other
I have an application that displays a ListView using a CursorAdapter that I have
I have a very simple application that use a 2 component UIPickerView that causes
We have an application that includes a voting component. To try and minimise voter
I have a large Compact Frameworks V2.0 application that in most cases works very

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.