Pete Freitag Pete Freitag

Getting Size of Heap and Non Heap Memory in CFML

Published on July 17, 2013
By Pete Freitag
coldfusionjava

I was helping out a member of my CFUG with some questions about the JVM, and I wanted to point him to a way to see how big his PermGen is at runtime. Back in the CF6 days I published some CFML code to get the heap memory usage, but that does not include the PermGen, so here's how you get it:

<cfset mf = CreateObject("java", "java.lang.management.ManagementFactory")>
<cfset memBean = mf.getMemoryMXBean()>
<cfset heapMem = memBean.getHeapMemoryUsage()>
<cfset nonHeapMem = memBean.getNonHeapMemoryUsage()>

<cfoutput>
Heap Memory: #Round(heapMem.getUsed()/1024/1024)#mb In Use 
	(#Round(heapMem.getCommitted()/1024/1024)#mb Committed,
	 #Round(heapMem.getMax()/1024/1024)# Max Allowed Size)<br />

Non Heap Memory (PermGen & Code Cache): #Round(nonHeapMem.getUsed()/1024/1024)#mb In Use 
	(#Round(nonHeapMem.getCommitted()/1024/1024)#mb Committed,
	 #Round(nonHeapMem.getMax()/1024/1024)# Max Allowed Size)
</cfoutput>

What is the PermGen / What does the PermGen Store?

The PermGen is short for Permanent Generation it is used to store loaded Java class information and metadata. Once you application is fully loaded and all code points have been executed your PermGen typically stays level, unless you are doing dynamic class loading (eg with JavaLoader or some other custom class loader.).



java coldfusion jvm heap cfml

Getting Size of Heap and Non Heap Memory in CFML was first published on July 17, 2013.

If you like reading about java, coldfusion, jvm, heap, or cfml then you might also like:

Fixinator

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.


Try Fixinator

CFBreak
The weekly newsletter for the CFML Community


Comments

Thanks David!
by Pete Freitag on 07/23/2013 at 12:19:00 PM UTC