The char array is used in java8 to construct the String memory footprint problem.

topic description

java8 saves 10000000 String, to view memory usage.

sources of topics and their own ideas

String objects are constructed in two different ways, and the memory footprint is very different. What is the reason and how to solve it:
1, new String ("ABCDEF"); memory occupancy 240MB
2, char [] chars = {"A", "baked," clocked, "dumped," egged,"F"}; new String (chars); occupies memory 240MB + 320MB = 560MB

related codes

the code of the first method is as follows:
public static void main (String [] args) throws InterruptedException {

int count = 10000000;
String[] array = new String[count];
for (int i = 0; i < count; iPP) {
    String e = new String("ABCDEF");
    array[i] = e;
}

}

clipboard.png

:
public static void main(String[] args) throws InterruptedException {


}

char[]320MB
clipboard.png

what result do you expect? What is the error message actually seen?

what is the reason and how to get rid of the 320MB memory occupied by the char array? thank you!

Jun.19,2021

the reason is simple

   

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb3557-4f91a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb3557-4f91a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?