Status/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Jonas Meller / Jonas Meller (Jonas Meller)
Created: 02/27/2012
Components: Performance
Versions: 9.0.1
Failure Type: Memory Leak
Found In Build/Fixed In Build: 9.0.1 /
Priority/Frequency: Major / Some users will encounter
Locale/System: English / Windows 7
Vote Count: 4
Problem Description:
You run out of memory if you create too many objects in one request even if you don't keep a reference to all those objects. This happens because ColdFusion keeps references to them all. The references are held in a private variable called dummyCompMap in getPageContext().getFusionContext().
I have run into this in an application that occasionally creates a lot of beans.
Steps to Reproduce:
Create the following two files and execute run.cfm.
TenMB.cfc:
<cfcomponent output="false">
<cffunction name="init" access="public" output="false" returntype="TenMB">
<cfset variables.byteArray = CreateObject('java','java.lang.reflect.Array').newInstance(CreateObject('java', 'java.lang.Byte').TYPE, 10000000) />
<cfreturn this />
</cffunction>
</cfcomponent>
run.cfm:
<cfloop from="1" to="1000" index="i">
<cfset CreateObject('component', 'TenMB').init() />
<cflog file="bug" text="i: #i#" />
</cfloop>
DONE
Actual Result:
java.lang.OutOfMemoryError: Java heap space
Expected Result:
DONE
Any Workarounds:
Workaround 1:
Each thread created with cfthread gets its own FusionContext so objects created in a thread are released when the thread finishes.
run_workaround1.cfm:
<cfloop from="1" to="1000" index="i">
<cfset threadName = CreateUUID() />
<cfthread action="run" name="#threadName#">
<cfset CreateObject('component', 'TenMB').init() />
</cfthread>
<cfthread action="join" name="#threadName#" />
<cflog file="bug" text="i: #i#" />
</cfloop>
DONE
Workaround 2:
Get access to dummyCompMap and clear it. I don't know what the side effects are.
run_workaround2.cfm:
<cfloop from="1" to="1000" index="i">
<cfset CreateObject('component', 'TenMB').init() />
<cfset fusionContext = getPageContext().getFusionContext() />
<cfset field = fusionContext.getClass().getDeclaredField('dummyCompMap') />
<cfset field.setAccessible(true) />
<cfset field.set(fusionContext, JavaCast('null', 0)) />
<cflog file="bug" text="i: #i#" />
</cfloop>
DONE
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3124148
External Customer Info:
External Company:
External Customer Name: J_M_84
External Customer Email:
Attachments:
- February 27, 2012 00:00:00: 1_bug.zip
Comments: