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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:14:45+00:00 2026-06-13T21:14:45+00:00

I have a question regarding the Java heap space. I have a program that

  • 0

I have a question regarding the Java heap space.

I have a program that uses geotools to create a graph from a street network.
I do some stuff with that but I run into a OutOfMemoryError but I am unsure why. I use the following code to get the amount of free memory.

Runtime rt = Runtime.getRuntime();
long maxMb = rt.freeMemory()/(1024*1024);
System.out.println("Your JVM has " + maxMb + " MB of memory left");

And when I run my program, there seems to be enough memory (see output). This console output is done right before the OutOfMemory Error occurs. So what is going wrong? When I enlarge the Java heap space, the OutOfMemory Error occurs nevertheless (but with 1461 MB left). I have no idea why that happens? Any ideas?

Your JVM has 981 MB of memory left
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at masterthesis.datastructures.Stroke.addStrokeSegment(Stroke.java:78)
at masterthesis.algorithms.StrokeBuilder.buildStroke(StrokeBuilder.java:145)
at org.geotools.test.Main.main(Main.java:109)
  • 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-13T21:14:46+00:00Added an answer on June 13, 2026 at 9:14 pm

    Since the output indicates that you have a lot of memory left and the error ocurrs during an array list growth my guess is that you have a really huge arraylist that you put objects in. When the JVM tries to grow the list you do not have enough heap space to accomodate the doubling in size of the list.

    I would investigate how many objects you actually put in your list with addStrokeSegment().

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

Sidebar

Related Questions

Following on from my recent question regarding parsing XML files in Java I have
I have a question regarding to the Java File class. When I create a
I have a question regarding methods that can return parameterized generic types in Java.
I have a question regarding the iterator behavior in Java. I have a call
I have some question over here regarding the java garbage collector. First let me
I have a question regarding the compatibility between different java versions. On my computer,
I have this very straight forward question regarding Thread and Timer classes in Java
I get a java.lang.OutOfMemoryError: Java heap space message when reading from an 11g Oracle
I have a question regarding the threads that my application spawns during execution and
I have a question regarding threading in Java. In my code, ... client.doSth(); //

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.