cffunction 内的内存泄漏循环 cfmodule [英] Memory Leak Looping cfmodule inside cffunction

查看:23
本文介绍了cffunction 内的内存泄漏循环 cfmodule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有一个根为 coldfusion.runtime.CFDummyComponent 的堆转储,请继续阅读.

Googlers if you've got a heap dump with a root of coldfusion.runtime.CFDummyComponent read on.

MXUnit 的 Marc Esher 成名在不同的上下文中发现了完全相同的错误.他的解决方案涉及一个大循环,通过从 query="name"from="1" to="#name.recordcount#" index="row".另一种可行的方法是在循环内使用 <cfthread> :

Marc Esher of MXUnit fame found the exact same bug in a different context. His solution involves a large loop over a query solved by going from query="name" to from="1" to="#name.recordcount#" index="row". Another approach that works is using <cfthread> inside the loop as such:

<cfloop ...>
    <cfset threadName = "thread" & createUuid()>
    <cfthread name="#threadName#">
        <!--- do stuff --->
    </cfthread>
    <cfthread action="join" name="#threadName#">
</cfloop>

当您遇到需要在循环内执行诸如查询和 之类的情况时,这非常有效,以便消耗的内存仅用于该迭代.

This is very effective when you run into situations where you need to do things inside the loop like queries and <cfmodule> inside <cffunction> so that the memory consumed is only for that iteration.

希望其他人可以确认或告诉我我做错了什么.通过调用文件 oom.cfm(如下所示),我能够始终如一地重现运行的 OOM.使用 jconsole 我可以看到请求消耗了内存并且在完成之前永远不会释放它.问题似乎是在 <cffunction> 内部调用 <cfmodule>,如果我注释掉 <cfmodule> 调用的东西在请求运行时被垃圾收集.

Hoping someone else can confirm or tell me what I'm doing wrong. I am able to consistently reproduce an OOM running by calling the file oom.cfm (shown below). Using jconsole I am able to see the request consumes memory and never releases it until complete. The issue appears to be calling <cfmodule> inside of <cffunction>, where if I comment out the <cfmodule> call things are garbage collected while the request is running.

ColdFusion 版本:9,0,1,274733

ColdFusion version: 9,0,1,274733

JVM 参数

java.home=C:/Program Files/Java/jdk1.6.0_18
java.args=-server  -Xms768m -Xmx768m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=512m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/ -Djava.security.policy={application.home}/servers/41ep8/cfusion.ear/cfusion.war/WEB-INF/cfusion/lib/coldfusion.policy -Djava.security.auth.policy={application.home}/servers/41ep8/cfusion.ear/cfusion.war/WEB-INF/cfusion/lib/neo_jaas.policy -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=56033

测试用例

oom.cfm(这在下面调用 template.cfm - Adobe 错误 #85736)

Test Case

oom.cfm (this calls template.cfm below - Adobe Bug #85736)

<cffunction name="fun" output="false" access="public" returntype="any" hint="">
    <cfset var local = structNew()/>
    <!--- comment out cfmodule and no OOM --->
    <cfmodule template="template.cfm">
</cffunction>

<cfset size = 1000 * 200>
<cfloop from="1" to="#size#" index="idx">
    <cfset fun()>
    <cfif NOT idx mod 1000>
        <cflog file="se-err" text="#idx# of #size#">
    </cfif>
</cfloop>

template.cfm

<!--- I am empty! --->

更新 #2(cfthread 案例来自 Elliott Sprehn - Adobe ColdFusion 错误 #83359)

<cfthread name="test">  
  <cfloop from="1" to="10000" index="i">      
    <cflog text="This is very bad.">      
    <cflock name="test" timeout="10">      
    </cflock>  
  </cfloop>  
  <!--- Sleep a very long time (10 minutes) --->  
  <cfset sleep(600000)>
</cfthread>

推荐答案

我以前没有遇到过,但我认为是这样的:

I've not run into this before, but here's what I think is going on:

每次调用 cfmodule 时,都会为其创建一个新的内存空间(IIRC 是它与 cfinclude 之间的主要区别).因为您在函数内调用 cfmodule,所以 cfmodule 内存空间在技术上属于该函数的内存空间.在函数完成之前,函数的内存受到垃圾回收的保护.结果:堆满,你得到一个OOM错误.

Each time cfmodule is called, a new memory space is created for it (which, IIRC, is the main difference between it and cfinclude). Because you are calling the cfmodule within the function, the cfmodule memory space technically belongs to that function's memory space. The function's memory is protected from garbage collection until the function is done. Result: heap fills, and you get an OOM error.

我认为将其称为内存泄漏是不正确的,因为它的行为正确,并且当函数完成时,垃圾收集器可以清除对该内存的保留.但是,我可以看到它可能不方便.

I don't think calling this a memory leak is correct, as it is behaving correctly, and when the function completes, the garbage collector can clear the hold on that memory. However, I can see how it might be inconvenient.

这篇关于cffunction 内的内存泄漏循环 cfmodule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆