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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:04:42+00:00 2026-06-15T02:04:42+00:00

When i run the below program i got the exception when for loop begins

  • 0

When i run the below program i got the exception when for loop begins its execution at i=1031521. How to over come memory usage of this type?

class wwww
    {
        public static void main(String args[])
        {
            String abc[]=new String[4194304];
            String wwf="";
            int s_count=524286;
            for(int i=0;i<4194304;i++)
            {
                System.out.println("----------enter--------"+i);
                abc[i]=""+i;
                System.out.println("----------exit--------"+i);
            }
        }
    }

The exception is:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2882)
    at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.
java:100)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390
)
    at java.lang.StringBuilder.append(StringBuilder.java:119)
    at wwww.main(wwww.java:12)
  • 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-15T02:04:44+00:00Added an answer on June 15, 2026 at 2:04 am

    This is because your your uses up all the heap space allocated to your jvm.

    You can use argument while running the program to specify the heap size that you would like to allocate.

    This is an example:

    java -Xmx256m MyClass
    

    Here a maximum of 256 MB of heap space will be allocated

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

Sidebar

Related Questions

As you can see below, I have Parallel.For loop. If run the program while
When i run the command below: 127.0.0.1:8080/solr/suggest?spellcheck.build=true I got an exception as below, anyone
I'm using Netbeans. When I run the program below, I get this as output
I have run this program below with a symbol_list of a few hundreds symbol
This program below when run does not halt. I don't think I made a
I am getting a weird exception when I exit the program. This has started
I've got a very simple java program (J.java, see below) on my application server
Why does the program listed below run on mac osx and linux but not
When I run the below program I am getting the following errors: (any ideas?)
After sometime, its happened unexpected error Error: Cannot run program jar: CreateProcess error=2, The

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.