Getting Size of Heap and Non Heap Memory in CFML
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.).
- Updating Java on ColdFusion or Lucee - March 21, 2019
- Adobe Says Go Ahead and Upgrade your ColdFusion JVM - October 24, 2012
- OutOfMemoryError - GC overhead limit exceeded - March 25, 2010
- Serializing CFC's in ColdFusion 8 - August 6, 2007
- Null Java References in CF 6 vs 7 - January 10, 2006
Check out the following ColdFusion component as an example on accessing the statistics (Testing in CF10, should work in CF9, Java methods should work from CF6+, untested on Railo but should work).
- Updating Java on ColdFusion or Lucee
- ColdFusion returning empty response with server-error: true
- Careful applying CF11u16, CF2016u8, CF2018u2
- Sessions don't work in Chrome but do in IE
- csrfVerifyToken does not invalidate the token
- The cf_sql_ is optional in cfqueryparam
- Cookie Expires / Max-Age 1969-12-31T23:59:59.000Z
- Burst Throttling on AWS API Gateway Explained