Skip to content

Instantly share code, notes, and snippets.

@petebankhead
Created June 25, 2021 09:08
Show Gist options
  • Save petebankhead/40520366791ef8fe0ab0ca3403812d8d to your computer and use it in GitHub Desktop.
Save petebankhead/40520366791ef8fe0ab0ca3403812d8d to your computer and use it in GitHub Desktop.
Print out various memory-related values in QuPath
/**
* Script to help track down memory leaks.
* Uses JavaCPP, some useful info at https://javadoc.io/static/org.bytedeco/javacpp/1.5.5/org/bytedeco/javacpp/Pointer.html
*
* @author Pete Bankhead
*/
import org.bytedeco.javacpp.Pointer
System.gc()
//Pointer.trimMemory() // Private!
println "Runtime:"
var rt = Runtime.getRuntime()
printBytes(" maxMemory() ", rt.maxMemory())
printBytes(" totalMemory() ", rt.totalMemory())
printBytes(" freeMemory() ", rt.freeMemory())
def usedMemory = (rt.totalMemory() - rt.freeMemory())
printBytes(" Memory used ", usedMemory)
println("")
println "Pointer:"
printBytes(" maxBytes() ", Pointer.maxBytes())
printBytes(" maxPhysicalBytes()", Pointer.maxPhysicalBytes())
printBytes(" totalBytes() ", Pointer.totalBytes())
printBytes(" physicalBytes() ", Pointer.physicalBytes())
try {
println("")
println " Total count: \t${Pointer.totalCount()}"
println("")
} catch (Throwable t) {
println ' Total count not available'
}
println "Operating system:"
printBytes(" Total: ", Pointer.totalPhysicalBytes())
printBytes(" Available: ", Pointer.availablePhysicalBytes())
void printBytes(String name, long n) {
println "$name \t${n / (1024 * 1024)} MB"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment