Qiaosheng's profile没有的空间PhotosBlogLists Tools Help

Blog


    September 25

    GC of "new String()"

    Quited different between " " and new String(" "), if String contents are equal.

    Test1:
     
     Set<String> collection = new HashSet<String>();
     String sql = null;
      for ( int i=0; i<100000; i ++ ){
         sql = "xyz";
         collection .add(sql);
     }
     System.out.print("done. You can check the jvm"); 
     Thread.sleep(10000);
     
     
     num   #instances    #bytes  class name
    --------------------------------------
      1:       523       87208  [C
      2:       135       47920  [B
      3:        12       31096  [I
      4:       323       13824  [Ljava.lang.Object;
      5:        32       10240  <objArrayKlassKlass>
     
    6:       385        9240  java.lang.String
      7:        92        4416  java.nio.HeapCharBuffer
      8:        91        4368  java.nio.HeapByteBuffer
      9:        42        4032  java.lang.Class
     10:        55        3960  java.lang.reflect.Field
     11:        56        1888  [Ljava.lang.String;
     12:        11        1720  <constMethodKlass>
     13:        45        1472  <symbolKlass>
     14:        18        1440  [Ljava.util.HashMap$Entry;
     15:        58        1392  java.util.Hashtable$Entry
     16:        10        1040  [Ljava.util.Hashtable$Entry;
     17:        61         976  java.lang.StringBuilder
     
     
    Test 2:
     
    Set<String> collection = new HashSet<String>();
     String sql = null;
      for ( int i=0; i<100000; i ++ ){
         sql = new String( "xyz");
         collection .add(sql);
     }
     System.out.print("done. You can check the jvm"); 
     Thread.sleep(10000);
     
     
    num   #instances    #bytes  class name
    --------------------------------------
      1:     31782      762768  java.lang.String
      2:       212       45528  [C
      3:        17       25520  [B
      4:        58       21632  [I
      5:       312       13024  [Ljava.lang.Object;
      6:        32       10240  <objArrayKlassKlass>
      7:        42        4032  java.lang.Class
      8:        47        3384  java.lang.reflect.Field
      9:        11        1728  <constMethodKlass>
     10:        48        1648  [Ljava.lang.String;
     11:        45        1472  <symbolKlass>



    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://devoteinjava.spaces.live.com/blog/cns!908208BAA1B1702!170.trak
    Weblogs that reference this entry
    • None