Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to minimize the memory used by my application?
    primarykey
    data
    text
    <p>I'm writing a Java/Swing application with ~30 class my probleme is when i run my programe it load more than <strong>150 M</strong> of the memory, is that normal ? since the application have 4 threads, parse some XML files, load some icon file, and drow some Jfreechat charts. if not how can i do to minimize the amount of memory used by the application, is affecting some variables to null help? is loading the XML files once to use them in all the application life cycle help or i have to load them evry time i need them? is there some other tips that help me? </p> <p>PS: im devlopping with a 8G memory computer in case that can affect the memory used by my program. </p> <p><strong>EDIT:</strong> it appeared that the program don't occupy all the 150MB because i get this value from the top command on linux, by running this code in my application as <a href="https://stackoverflow.com/users/11662/vilmantas-baranauskas">vilmantas</a> advises me:</p> <pre><code> long free = Runtime.getRuntime().freeMemory(); long total = Runtime.getRuntime().totalMemory(); long max = Runtime.getRuntime().maxMemory(); long used = total - free; </code></pre> <p>I found that he occupy much less than that (~40MB) so i decide to run it with <strong>"-Xmx40M"</strong> argument and i reduce more than 40% of memory usage in the Top command. The problem who are occupying the rest of memory since JVM <em>(as i know)</em> have his own process <strong>?</strong> and how to make this operation automatic**?** because when choosing a not appropriate value you can get a memory exception as i have by running with <strong>"-Xmx30M"</strong> argument:</p> <pre><code> Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space </code></pre>
    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.
 

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