1

I try to get the memory usage for the LinkedList, but it always return 0.

<%
    Runtime runtime = Runtime.getRuntime();

    java.text.DecimalFormat df = new java.text.DecimalFormat("###,###.##");
    long start = runtime.freeMemory();

    java.util.LinkedList list = new java.util.LinkedList();
    for (int i = 0; i < 100; i++)
        list.add("asd");

    System.out.println(df.format(start - runtime.freeMemory()));
%>

Is there anyway better way to get the memory usage for thread or object?

XYZ
  • 41
  • 4
  • possible duplicate of [In Java, what is the best way to determine the size of an object?](http://stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object) – Thilo Oct 08 '14 at 05:21
  • @Thilo - I saw that method, and I don't think we can apply on Java Web. Above code is just a simple way to test out, maybe I should change it into jsp. – XYZ Oct 08 '14 at 07:18

0 Answers0