Skip to content

Commit

Permalink
Merge pull request #15 from sroughley/Fix_GetHeapUsage_Exception
Browse files Browse the repository at this point in the history
Fix possible IAE in getHeapUsage()
  • Loading branch information
sverhoeven authored Mar 25, 2024
2 parents 1fa09ac + 7109fff commit 7148ac7
Showing 1 changed file with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
package nl.esciencecenter.e3dchem.knime.testing.core.ng;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryType;
import java.lang.management.MemoryUsage;

import org.eclipse.core.runtime.IProgressMonitor;
Expand Down Expand Up @@ -120,20 +118,6 @@ public void aboutToStart() {
protected static MemoryUsage getHeapUsage() {
System.gc();

long initMem = 0;
long maxMem = 0;
long committedMem = 0;
long usedMem = 0;
for (MemoryPoolMXBean memoryPool : ManagementFactory.getMemoryPoolMXBeans()) {
if (memoryPool.getType().equals(MemoryType.HEAP) && (memoryPool.getCollectionUsage() != null)) {
MemoryUsage usage = memoryPool.getUsage();

initMem += usage.getInit();
maxMem += usage.getMax();
committedMem += usage.getCommitted();
usedMem += usage.getUsed();
}
}
return new MemoryUsage(initMem, usedMem, committedMem, maxMem);
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
}
}

0 comments on commit 7148ac7

Please sign in to comment.