Skip navigation
Wimpie
Currently Being Moderated

CFC memory leak? Why is this happening? Simple CFC running out of memory...

Dec 22, 2009 11:41 PM

Take a look at this, a very simple cfm and cfc. Start the cfm, which calls the cfc thousands of times. Look at the JVM memory usage: it climbs up and up till ColdFusion slows down and halts with an out of memory error after about ten minutes. I haven't got a clue on how to resolve this...

 

test.cfm

 

<cfsetting enablecfoutputonly="Yes" requesttimeout="10000">
<cfset functions=createobject("component","test")>
<cfloop from="1" to="50000" index="i">
  <cfset returnArray=functions.remoteDataGet()>
</cfloop>

<cfoutput>READY</cfoutput>

 

test.cfc

 

<cfcomponent>
<cffunction name="remoteDataGet" access="remote" output="false" returntype="query">
  <cfreturn querynew('test','Integer')>
</cffunction>
</cfcomponent>

 
Replies
  • Currently Being Moderated
    Dec 23, 2009 1:37 AM   in reply to Wimpie

    It might be an idea to raise a bug report: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html.

     

    Also, it's possible for users to annotate the online docs, so it might be an idea to add a comment to the relevant page.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 23, 2009 7:43 AM   in reply to Wimpie

      <cfreturn querynew('test','Integer')>

     

    While probably unrelated to the memory issue, is not "Integer" a reserved word in queries?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 23, 2009 8:05 AM   in reply to -==cfSearching==-

    Regarding,

    While probably unrelated to the memory issue, is not "Integer" a reserved word in queries?

     

    It is.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2009 2:21 AM   in reply to Wimpie

    The cause of the memory leak is obvious. There's just that much straw you can load on the camel's back.

     

    Think var! Then you give Coldfusion at least a chance to offload some of the garbage.

     

    <cfcomponent>
    <cffunction name="remoteDataGet" access="remote" output="false" returntype="query">

      <cfset var qry = querynew('test','Integer')>
      <cfreturn qry>
    </cffunction>
    </cfcomponent>

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2009 2:23 AM   in reply to Adam Cameron.

    It might be an idea to raise a bug report: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html.

     

    Nein. Keine need.


     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2009 3:35 AM   in reply to Wimpie

    Wimpie last logged in two days ago. Yet someone (else?) has just marked this thread as answered. What's going on here?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2009 10:23 AM   in reply to Wimpie

    Re: CFC memory leak? Why is this happening? Simple CFC running out of memory...

     

    With or without VAR, the problem remains. Turn on memory profiling, and all memory gets eaten up... the solution is to turn memory profiling OFF, so yes, this question has been answered (by myself, look at the top). And YES, a bug report is filed.

     


    I ran your exact code, with profiling switched on, with and without using var, and couldn't reproduce the issue in either case. In any case, the problem is apparently with the profiler, not with a "Simple CFC running out of memory". So your description of the problem isn't entirely correct. The test creates CFCs and query objects 50000 times. There is the crux of the problem.

     

    What I know is, garbage collection is unpredictable. It is apparent that, in your test, objects pile up in memory, and don't get garbage-collected quick enough. I can imagine the same thing happening when you turn debugging on.  Server monitoring and debugging are processes that may be processing each and every object your application creates, without allowing the garbage-collector enough room for action.

     

    You may or may not have found a bug. It is worth investigating anyway. That way, we'll know more.

     

    You marked the problem as solved without as much as one word of clarification. Just as well I asked. Otherwise, you would have left a misleading impression.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2009 11:29 AM   in reply to Wimpie

    Just in case anyone else comes across this and wants to know what the bug ref is, it's: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#b ugId=81318

     

    To yhe OP: it's helpful if you cross-ref any bugs you raise back to the forum post relating to them, for anyone else who has the same issue later.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2009 7:01 AM   in reply to Wimpie

    I have been playing with your test scenario. Whatever combination I used, I couldn't reproduce an out-of-memory error.

     

    You can use my code, or similar, to study memory use during profiling. I include it below.

     

    I indeed ran out of memory, but that was when I experimented by adding 2 memory consuming operations. First, I created the component objects within the loop. Secondly, I stored them in an array. (See the code I commented out).

     

    <cfsetting enablecfoutputonly="Yes" requesttimeout="1800">

     

    <cfset testObj=createobject("component","test")>

     

    <!--- <cfset testObjArray = arrayNew(1)> --->

     

    <!--- Instantiate Coldfusion Administrator CFC and log in --->

     

    <cfset createObject("component","cfide.adminapi.administrator").login("your_ admin_password")>

     

    <!--- Instantiate Server Monitor CFC --->

     

    <cfset serverMonitorObj = createObject("component","cfide.adminapi.servermonitoring")>

     

    <!--- Instantiate Java Runtime --->

     

    <cfset runtime = CreateObject("java","java.lang.Runtime").getRuntime()>

     

    <cfloop from="1" to="50000" index="i">

     

        <cfset returnQuery=testObj.remoteDataGet()>

     

        <!---

     

        <cfset testObjArray[i]=createobject("component","test")>

     

          <cfset returnQuery=testObjArray[i].remoteDataGet()>

     

        --->

     

        <cfif (i-1)/5000 eq int((i-1)/5000)><!--- test at every multiple of 5000 --->

     

            <!--- Calculate percentage of JVM allocated memory that is free --->

     

            <cfset freeMemory = runtime.freeMemory()>

     

            <cfset totalAllocatedMemory = runtime.totalMemory()>

     

            <cfset fractionFreeMemory = freeMemory/totalAllocatedMemory>

     

            <cftry>

     

                <!--- If free memory is less than 5%, disable memory monitoring and profiling --->

     

                <cfif fractionFreeMemory LT 0.05>) {

     

                    <cfset serverMonitorObj.disableMemoryMonitoring()>

     

                    <cfset serverMonitorObj.disableProfiling()>

     

                    <cfoutput>Memory monitoring and profiling have been disabled, because JVM free memory fell down to #round(fractionFreeMemory*100)#%<br></cfoutput>

     

                    <cfbreak>

     

                </cfif>

     

            <cfcatch type="any">

     

                Error invoking methods in Server Monitor. Bad admin password or server monitor possibly not enabled.

     

                <br>

     

                <!--- <cfdump var="#cfcatch#"> --->           

     

                <cfbreak>

     

            </cfcatch>   

     

            </cftry>

     

        </cfif>

     

    </cfloop>

     

    <br>


    <cfoutput>READY</cfoutput>

     

     


     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2009 8:10 AM   in reply to Wimpie

    Oh, perhaps the most important question to start with: what is the JVM heap size of your Coldfusion installation? If it is low, say, less than 100MB, the chance of out-of-memory errors will be high.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points