I'm having issues with ColdFusion's heap. Here's a little example application I'm experimenting with. I thought after cfinvoke
calling the init
method it destroys all variables local to the component. But apparently it's not the case. The application works as it is below but if I add a zero to the loop in index.cfm
it breaks. What's stored in the heap to cause that? Is there a way around this?
index.cfm:
<cfloop from="1" to="1000" index="i">
<cfinvoke component="test" method="init" returnvariable="x">
</cfloop>
<cfoutput><p>#x#</p></cfoutput>
test.cfc:
<cfcomponent output="false">
<cffunction name="init" returntype="string">
<cfset var test = structNew()>
<cfloop from="1" to="1000" index="i">
<cfset test[i] = i>
</cfloop>
<cfreturn Now()>
</cffunction>
</cfcomponent>
And here's the error message:
SEVERE: Servlet.service() for servlet CfmServlet threw exception
javax.servlet.ServletException: ROOT CAUSE:
java.lang.OutOfMemoryError: Java heap space`
Any help would be appreciated.
This is a known problem and CURRENTLY there is no way around it. It seems that CF DOES NOT handle garbage collection properly. As far as I can tell it will not destroy and free up memory used by component until after the request has finished.
Because of that, depending on how many properties your components has will determine how many of them you can create until you get the heap error.
I know this doesn't help your problem, but at least now you can take measures to prevent it.