Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to be more specific about what you are trying to achieve. There are two goals that are (in some cases) contradictory:</p> <ul> <li>minimizing the number of objects that are allocated, and hence the number of times the GC runs,</li> <li>minimizing the amount of heap space that is used for live objects, and hence the "footprint" of your application.</li> </ul> <blockquote> <p>static: wise use of static</p> </blockquote> <p>This is meaningless advice, unless you say what "wise use" is.</p> <blockquote> <p>String: wise use of String, try to use as local variables, make sure that there are no string without references and try to use StringBuffer or StringBuilder</p> </blockquote> <ul> <li>Wise use is meaningless advice; see above. </li> <li>Making sure there are no strings without references is meaningless because every string has a reference.</li> <li>Trying to use local variables is useful, but not always applicable. Sometimes using a static or instance variable could reduce the number of times you create new strings. Sometimes assigning an intermediate string to a local variable could increase its lifetime.</li> <li>You shouldn't use StringBuffer for string assembly.</li> <li>There are many cases where using a StringBuilder in string assembly does not help, and just makes the code harder to read. In general StringBuilder should only be used if you can't do the string assembly in one expression.</li> </ul> <blockquote> <p>Instance variables: try to declare variables locally as far as possible</p> </blockquote> <p>This is sound advice generally, though it needs to be balanced with other things.</p> <blockquote> <p>objects: reuse as far as possible</p> </blockquote> <p>This is bad advice. </p> <p>Reuse "as far as possible" means object pools, and object pools tend to use <strong>more</strong> heap space than if you just dropped the object and let the GC reclaim it. Object pools should only be used if it is critical that you minimize the object creation rate. Even then you need to be very careful to avoid:</p> <ul> <li>leaking objects by not returning them to the pool</li> <li>issuing "dirty" objects from the pool</li> <li>bugs as a result of the extra complexity, and</li> <li>wasting memory (e.g. on the pool data structures, and idle objects in the pool) and therefore making the GC run more often.</li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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