Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>split maybe aspect memory if you just want to use one or few arrays of the long string. the long string will always in memory. like</p> <pre><code>private static List&lt;String&gt; headlist = new ArrayList&lt;String&gt;(); String longstring = "....."; headlist.add(longstring.split(" ")[0]); </code></pre> <p>than the longstring will always in memory. JVM cannot gc it.</p> <p>in this situation, I think maybe you can try</p> <pre><code>private static List&lt;String&gt; headlist = new ArrayList&lt;String&gt;(); String longstring = "....."; headlist.add(new String(longstring.split(" ")[0])); </code></pre> <p>as following code</p> <pre><code>import java.util.ArrayList; import java.util.List; import java.util.Random; public class SplitTest { static Random rand = new Random(); static List&lt;String&gt; head = new ArrayList&lt;String&gt;(); /** * @param args */ public static void main(String[] args) { while(true) { String a = constructLongString(); head.add(a.split(" ")[0]); //1 //head.add(new String(a.split(" ")[0])); //2 if (i % 1000 == 0) System.out.println("" + i); System.gc(); } } private static String constructLongString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i &lt; 10; i++) { sb.append(rand.nextInt(10)); } sb.append(" "); for (int i = 0; i &lt; 4096; i++) { sb.append(rand.nextInt(10)); } return sb.toString(); } } </code></pre> <p>if you running with -Xmx60M, it will outofmemory about 6000+ and if you using code line 2, comment the line 1, then it running long time more bigger than 6000</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload