Rob Gonda's Blog

Watch out for memory leaks!

I had a server constantly running out of memory and I just couldn't figure out what was wrong. The first thing I did, thanks to Steven Erat, was enable the jrun metrics to monitor threads, sessions, and jvm memory. You do this by editing the \runtime\servers\coldfusion\SERVER-INF\jrun.xml and set <attribute name="metricsEnabled">true</attribute>. I debugged my caching system, fixed some garbage collection issues, but it still did not completely fixed my problem.
A few days later, I got an insight: the onSessionStart and onSessionEnd functions.

I had the following functions defined:

    <!--- on Session Start --->
    <cffunction name="onSessionStart">
        <cfscript>
            application.com.objectFactory.getInstance('session').addSession(session);
        </cfscript>
    </cffunction>

   
    <!--- on Session End --->
    <cffunction name="onSessionEnd">
        <cfargument name="SessionScope" required="Yes" />
        <cfargument name="ApplicationScope" required="No" />
        <cfscript>
            ApplicationScope.com.objectFactory.getInstance('session').delSession(arguments.SessionScope.sessionId);
        </cfscript>
    </cffunction>


Well, guess what, it seems like even after removing the reference to the specific session, ColdFusion failed to destroy it. I would have assumed that ColdFusion would just destroy the session, and if I happen to still be pointing to it I would get the famous null pointer exception, but no, ColdFusion kept a copy of some sort draining all my memory. As soon as I removed the reference to the session, the jrun garbage collection did its job and memory because stable again.

I will try to look further into this behavior using the Scorpio Server Monitoring, which includes really nice tools to analyze what's using your precious RAM.

TrackBacks
There are no trackbacks for this entry.

Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?C7D3CCF4-3048-7431-E46E9B5FA0036C3C

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
This blog is running version 5.9.003. Contact Blog Owner