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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:39:04+00:00 2026-06-12T13:39:04+00:00

String[] stringArray = new String[] { abc, xyz }; Executing this line there are

  • 0

String[] stringArray = new String[] { "abc", "xyz" };

Executing this line there are two String literals created “abc” and “xyz” in PERMGEN space. Since the initialization has a new operator I am not sure if there’s any memory allocated on HEAP.

Thanks guys.

  • 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-12T13:39:05+00:00Added an answer on June 12, 2026 at 1:39 pm

    All objects, except string literals, are created on the heap. From Java 7, string literals are created on the heap as well.

    In theory, escape analysis can prevent new object from being created on the heap and perhaps using the stack instead. This rarely happens in practice AFAIK.


    In answer to EJP question, I haven’t fund a non trivial example but

    From http://www.oracle.com/technetwork/server-storage/ts-7392-159315.pdf page 22

    New Technology: Escape Analysis
    Definition: An object escapes the thread that allocated it if
    some other thread can ever see it
    If an object doesn't escape, we can abuse it
    • Object explosion: allocate object's fields in different places
    • Scalar replacement: store scalar fields in registers
    • Thread stack allocation: store fields in stack frame
    • Eliminate synchronization
    • Eliminate initial object zero'ing
    • Eliminate GC read / write barriers
    Enabled with -XX:+DoEscapeAnalysis in JDKTM version 6
    

    In theory this feature has been there for some time, but it didn’t work particularly often (even find a contrived example was hard) In Java 7, finding contrived examples is easier. 😉

    public class UsesWrappersMain {
        public static void main(String... args) {
            for (int j = 0; j < 10; j++) {
                long used = used(), count = 0;
                for (int i = 0; i < 2000; i++) {
                    count += printSum();
                }
                // add an object to show it is working
                byte[] b = new byte[16];
                long used2 = used();
                System.out.printf("Memory used for %,d iterations was %,d bytes%n", count, used2 - used);
            }
        }
    
        private static int printSum() {
            int count = 0;
            for (float i = 0; i < 10000; i++) {
                // definitively not autoboxed.
                Float j = new Float(i);
                count++;
            }
            return count;
        }
    
        private static long used() {
            return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        }
    }
    

    prints when run with -XX:-UseTLAB

    Memory used for 20,000,000 iterations was 480,888 bytes
    Memory used for 20,000,000 iterations was 32 bytes
    Memory used for 20,000,000 iterations was 32 bytes
    Memory used for 20,000,000 iterations was 32 bytes
    Memory used for 20,000,000 iterations was 32 bytes
    Memory used for 20,000,000 iterations was 32 bytes
    Memory used for 20,000,000 iterations was 32 bytes
    Memory used for 20,000,000 iterations was 0 bytes
    Memory used for 20,000,000 iterations was 0 bytes
    Memory used for 20,000,000 iterations was 0 bytes
    

    if you add -XX:-DoEscapeAnalysis which is not the default

    Memory used for 20,000,000 iterations was 320,000,928 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,144 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    Memory used for 20,000,000 iterations was 320,000,032 bytes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an array below string stringArray = new stringArray[12]; stringArray[0] = 0,1; stringArray[1]
Consider a string array shaped like this: string[] someName = new string[] { First,
Whi with this code public final String[] array_titoli_serie_prima = new String[]{ getResources().getString(R.string.titolo_p1), getResources().getString(R.string.titolo_p2), getResources().getString(R.string.titolo_p3),
I am trying to get a stringArray resource with this code: String continent =
I have a string array abc I put this in a for each loop.
Well, I have a string array: String array[] = new String[5]; array[0]=abc; array[1]=aab; array[2]=aaacb
I have a string array: string[] authors = new string[3]; authors[0] = Charles Dickens;
I am binding string array to the Repeater Control, string[] strPageSize = new string[25];
I need an advice about how to create new string array from 4 different
It's very simple. List<string> stringArr = new List<string>(); foreach (var item in db.IconTags) {

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.