Coldfusion.util.Key Memory Leak - a problem with structural keys?

Subsequently, I can throw a Java Heap Space OutOfMemory exception with the following ColdFusion 9.01 code (not tried earlier versions):

<cfset uuidGenerator = createObject("java", "java.util.UUID")>
<cfset transient = structNew()>
<cfloop from="1" to="100000" index="index">
    <cfset transient[uuidGenerator.randomUUID().toString()] = true>
</cfloop>

The above code uses the Java UUID class because it is faster than ColdFusion. The structure itself does not exist after the request (i.e., it is not in some constant region, such as application).

As a test, I generate a bunch of heaps right after server initialization. Then I run this code several times and see the completed generation via jConsole. After that, I run another bunch. Using the Eclipse memory analysis report, I see one large object based on coldfusion.util.Key.

I ask here, in the hope that others are faced with a similar problem, and if so, what have they done to get around this.

+5
source share
3 answers

Not an ideal solution, but until Adobe fixes a memory leak inside, you can access the private member ConcurrentHasMap on the coldfusion.util.Key object and manually clean it.

We set a scheduled task to complete this night, and then complete the GC right after that.

Compile this into a JAR file and put it somewhere in your path to the ColdFusion class.

import coldfusion.util.Key;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

class KeyEx
{
    public KeyEx()
    {
    }

    public void resetCache(Object k)
    {
        try
        {
            Field f = Key.class.getDeclaredField("keys");
            f.setAccessible(true);
            ConcurrentHashMap chm = (ConcurrentHashMap)f.get(k);
            chm.clear();
        }
        catch (Exception ex)
        {
            System.out.println("ZOMG something went epically wrong!");
        }
    }
}

And then you can just instantiate a new KeyEx object in coldfusion and call resetCache, passing in coldfusion.util.Key singleton.

<cfset keys = createObject("java", "coldfusion.util.Key") />
<cfset x = createObject("java", "KeyEx").init() />
<cfset x.resetCache(keys) />
+3
source

, , :

- MemoryLeak.cfm

<cfset transient = structNew() />
<cfset base = getTickCount() />
<cfloop from="1" to="10000" index="index">
  <cfset transient[hash("#base##index#")] = true >
</cfloop>
<cfoutput>
Done
</cfoutput>

- NoMemoryLeak.cfm

 <cfset transient = structNew() />
 <cfloop from="1" to="10000" index="index">
 <cfset transient[hash("#index#")] = true >
 </cfloop>
 <cfoutput>
 Done
 </cfoutput>

MemoryLeak.cfm CF 9.01+ 100 , . JVM NoMemoryLeak.cfm , , OldGen . 500 000 , .

OrangePips # CF (, ?), https://bugbase.adobe.com/index.cfm?event=bug&id=3119991 ToFix.

+2

, , . , coldfusion.util.Key.keys ConcurrentHashMap coldfusion.util.Key , . , .jar .class -/lib/cfusion.jar - , . , , .

, , , . , ColdFusion. , , , .

, , , , , , , . :

try {
  throw new RuntimeException();
} catch (Exception e) {
  e.printStackTrace(System.out);
}

cfusion.jar.

, .cfm . CF ( jrun.exe -start coldfusion), , System.out, . , , .

.cfm, . , , VM. , .

0

All Articles