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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:18:14+00:00 2026-05-24T12:18:14+00:00

I was wrote a little scratch program to check the time of looping through

  • 0

I was wrote a little scratch program to check the time of looping through a 2 dimensional array by rows or columns, since I remembered that one way was much faster for large data sets, but I couldn’t remember which way. I ran into an interesting error when I ran my program though.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at testing.ForLoopTest.main(ForLoopTest.java:10)

Now in my test I am using a int[10000][10000] running from in eclipse with the default heap settings. I know that I can increase the heap size, but my gut tells me that this should run just fine without me needing to do that. Is this normal? Is there something silly in my code that I am not seeing?

Here is my code

public static void main(String[] args){
    final int arrSize = 10000;
    long start = 0;
    long rowFirstTime = 0;
    long colFirstTime = 0;
    int[][] arr = new int[arrSize][arrSize];

    start = System.currentTimeMillis();
    for(int x = 0; x < arrSize; x++){
        for(int y = 0; y < arrSize; y++){
            arr[x][y] = -1;
        }
    }
    rowFirstTime = System.currentTimeMillis() - start;
    start = System.currentTimeMillis();
    for(int y = 0; y < arrSize; y++){
        for(int x = 0; x < arrSize; x++){
            arr[x][y] = 0;
        }
    }
    colFirstTime = System.currentTimeMillis() - start;
    System.out.println("row time is " + rowFirstTime);
    System.out.println("col time is " + colFirstTime);
}

The error happens on array initialization, it doesn’t get to the for loops.

Thanks,
zdevex

  • 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-24T12:18:14+00:00Added an answer on May 24, 2026 at 12:18 pm

    You are trying to allocate memory for 10 000 arrays of length 10 000. This requires lots of memory (about 400 MiB, by a raw calculation), which are unavailable in your JVM. This causes your OutOfMemoryError.

    Try to augment the amount of memory allocated to your JVM in the execution arguments. You are looking at something like the -Xmx argument. Try giving it a value greater than 400 MiB. I think you might be able to change this value in the project properties in Eclipse.

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

Sidebar

Related Questions

I wrote a little program that solves 49151 sudoku's within an hour for an
I wrote a little Python program that looks though a directory (and its subdirectories)
So I wrote a little multithreaded SMTP program. The problem is every time I
I wrote a little daemon in Perl that calls up FFMpeg to encode a
I wrote a little Haskell program to find the area of a triangle, primarily
Some time ago I wrote a little piece of code to ask about on
I've been playing with Python for a while and wrote a little program to
I wrote a little utility class that saves BitmapSource objects to image files. The
I wrote a little Java servlet that would dynamically generate an image button given
I wrote a little program, which is working like a ping command(i use ICMPSendEcho2),

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.