Skip to content

Fix memory usage #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,36 +215,38 @@
<version>2.1</version>
</dependency>
</dependencies>
<!--


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.ds4h.imagej.Image_Alignment</mainClass>
</manifest>
</archive>
<!--
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
-->
</configuration>

<executions>
<execution>
<id>make-assembly</id> this is used for inheritance merges
<phase>package</phase> bind to the packaging phase
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
-->
</project>
22 changes: 9 additions & 13 deletions src/main/java/com/ds4h/model/util/MemoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.ds4h.model.imagePoints.ImagePoints;
import com.sun.management.OperatingSystemMXBean;
import ij.IJ;
import ij.ImagePlus;

import java.lang.management.ManagementFactory;
import java.util.List;

Expand All @@ -11,7 +13,7 @@
*/
public class MemoryController {

private final static double MEMORY_PERCENTAGE_LIMIT = 0.30;
private final static double MEMORY_PERCENTAGE_LIMIT = 30.0;

private MemoryController(){

Expand All @@ -25,18 +27,12 @@ private MemoryController(){
public static void controlMemory(final List<ImagePoints> imagePoints) throws OutOfMemoryError{
long memorySize = 0;
final long totalMemory = (IJ.maxMemory()/(1024*1024));
for(final ImagePoints img : imagePoints){
final int width = img.getWidth();
final int height = img.getHeight();
final int depth = img.getBitDepth();
memorySize += (((long) width *height*depth)/8);
}
memorySize = memorySize/(1024*1024);
IJ.log("[MEMORY SIZE IMAGE] TotalSize: " + memorySize);
IJ.log("[MEMORY SIZE IMAGE] Total Memory: " + totalMemory);
IJ.log("[MEMORY SIZE IMAGE] Percentage: " + (memorySize/(double)totalMemory));

if(memorySize/(double)totalMemory >= MEMORY_PERCENTAGE_LIMIT){
final long currentMemory = (IJ.currentMemory() / (1024 * 1024));
final double usedMemory = ((double) currentMemory / totalMemory) * 100;
IJ.log("[MEMORY SIZE IMAGE] TotalSize: " + currentMemory + " MB");
IJ.log("[MEMORY SIZE IMAGE] Total Memory: " + totalMemory + " MB");
IJ.log("[MEMORY SIZE IMAGE] Percentage: " + usedMemory + " %");
if(usedMemory >= MEMORY_PERCENTAGE_LIMIT){
throw new OutOfMemoryError(MemoryController.getError());
}
}
Expand Down