Note that there are some explanatory texts on larger screens.

plurals
  1. POfindbugs report wrong line number and suppress error?
    primarykey
    data
    text
    <p>I have a java class which use System.GC() to calculate memory usage. However when I run findbugs, it always report wrong line number. Question 1: I ran this with intellij findbugs plugin as well as findbugs native GUI. Same result. Am I doing something wrong here?</p> <ol> <li><p>util.MemoryTestBench.lotsOfGC() forces garbage collection; extremely dubious except in benchmarking code Class: MemoryTestBench (util) Line: 35 - 35 ====> which is Thread.sleep(100) ????????</p></li> <li><p>Dead store to handle Class: MemoryTestBench (util) Line: 23 - 23 ====> which is return usedMemory() - prevUsedMemory ?????</p></li> </ol> <p>Question 2: how can I suppress error DM_GC ? I tried @SuppressWarnings which didn't work.</p> <p>test code is as follows:</p> <pre><code>package util; import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; import edu.umd.cs.findbugs.annotations.SuppressWarnings; public class MemoryTestBench { @SuppressWarnings (value = "DM_GC", justification = "call GC to measure memory size") public static long calculateMemoryUsage(ObjectFactory factory) { Object handle = factory.makeObject(); long prevUsedMemory = usedMemory(); handle = null; lotsOfGC(); prevUsedMemory = usedMemory(); handle = factory.makeObject(); lotsOfGC(); return usedMemory() - prevUsedMemory; } private static long usedMemory() { return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); } private static void lotsOfGC() { for (int i = 0; i &lt; 20; i++) { System.gc(); try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } public static void showMemoryUsage(ObjectFactory factory) { long mem = calculateMemoryUsage(factory); System.out.println( factory.getClass().getSimpleName() + " produced " + factory.makeObject().getClass().getSimpleName() + " which took " + mem + " bytes"); } public static void main(String[] args) { showMemoryUsage(new BigConcurrentHashMapFactory()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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