Skip to content

Instantly share code, notes, and snippets.

@paulklinkenberg
Created January 19, 2022 15:31
Show Gist options
  • Save paulklinkenberg/f4b6937c5a8ed954523bbcc2e3dcdbfb to your computer and use it in GitHub Desktop.
Save paulklinkenberg/f4b6937c5a8ed954523bbcc2e3dcdbfb to your computer and use it in GitHub Desktop.
Lucee / CFML code to display the available memory, allocated memory, and max memory in html
<cfoutput>
#getMem()#
</cfoutput>
<cfscript>
function getMem(){
var runtime = createObject('java', 'java.lang.Runtime').getRuntime();
var maxMemory = runtime.maxMemory();
var allocatedMemory = runtime.totalMemory();
var freeMemory = runtime.freeMemory();
return "<hr/>Free memory: " & numberFormat(round((maxMemory-allocatedMemory+freeMemory) / 1024 / 1024), ',') & "MB (#round((maxMemory-allocatedMemory+freeMemory)/maxMemory *100)#%)<br/>"
& "Used memory: #round((allocatedMemory-freeMemory)/maxMemory *100)#%<br/>"
& "Allocated: " & round(allocatedMemory/maxMemory *100) & "%<br/>"
& "Max memory: " & round(maxMemory / 1024 /1024) & "MB<hr/>";
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment