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

  • Home
  • SEARCH
  • 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 8277873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:49:09+00:00 2026-06-08T08:49:09+00:00

I wrote a sample java application which allocates memory and then running forever. why

  • 0

I wrote a sample java application which allocates memory and then running forever.
why is the memory used by the survivor space 0kbytes ?!

    List<String> stringlist = new ArrayList<String>();

    while (true) {
        stringlist.add("test");
        if (stringlist.size() >= 5000000)
            break;
    }

    while (true)
        for (String s : stringlist);
  • 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-08T08:49:10+00:00Added an answer on June 8, 2026 at 8:49 am

    Because “test” is a String literal it will end up in permanent memory not heap.
    Memory size of objects you create is 5000000 + 4*2 ~ 5MB which will easily fit into Eden space.

    Modify

    stringlist.add("test");
    

    to

    stringlist.add(new String("test"));
    

    and you will get 5000000 * 4 * 2 =38MB which most probably will still fit into Eden. You can either increase your list size or String length to make sure you have survivors.

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

Sidebar

Related Questions

For a system monitoring Java application which currently runs on the command line and
In eclipse IDE,there is a standalone java application which reads files.The files are all
I wrote a simple program in java web forms but i am receiving the
I wrote simple load testing tool for testing performance of Java modules. One problem
a few years back in college I wrote TONS of simple little java programs...
I wrote a simple Util method to convert a String in Java to util.Date
I am trying to write a simple Java function that will take a list
I am trying to write a simple java program which returns me all the
I wrote the following sample code to see how ARC works @property (nonatomic, weak)
(WARNING: this is my first java application, coming from .NET, so don't bash me

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.