ColdFusion 7 Memory Leak

In working on Financial Peace University Online last year, I became aware of a really ugly memory leak that had developed in the app (thankfully it was still in development, not in production). It took a few days to track down, but when I found it, it proved to have some implications that applied to all our ColdFusion web apps.

I discovered that for each singleton instance of a cfc that the ColdSpring factories provided, a little memory was leaked and never garbage collected. I simplified things to remove Mach-II, ColdSpring, and eventually everything except the simplest form I could think of. A cfm would create an instance of a cfc that had a method in it that would return a reference to itself. Then the cfm would go through 100 iterations of calling that method and place the result in an array. So I would have an array with 100 references to the same object, and still, the memory leak was present.

Finally I noticed that on my cfc method, I hadn’t specified output=”false”, though I had specified it on the cfcomponent tag. Adding output=”false” to the method that returned a reference to the cfc cured the memory leak. It seems bizarre, but if a memory leak was obvious, it wouldn’t have made it into the release version of ColdFusion.

I’m curious though. What if you have a method that does produce output? Will setting output=”true” leak memory or does the leak only exist if the parameter is not set?

Also, how have you been testing for memory leaks. I have been dealing with similar issues but have been having a hard time tracking down the culprit. It seems there are a lot of people struggling with memory leaks in CF 7 and it seems that everyone is coming to different conclusions.

Just wanted to say you guy rock! (Glad to have met you guys from Dave Ramsey at BFusion/BFlex). Just wanted to let you know that this post helped me diagnose a memory leak in Mach-II (when reloading from the dashboard). It appears that this issue affect CF8 even with cumulative hot fix 3 which supposedly fixed a memory leak issue CFCs and memory scopes.

Also beware that I had to fix a bunch of missing output attributes in our ColdSpring copy as well. I’ll post a blog post about this later.