Orange is my favorite color

Not the sexiest post you’ll run across, but based on many people’s findings1,2, you need to have an explicit output=”false” on every cffunction in order to prevent memory leaks on Adobe ColdFusion 7 and CF8. This is not a new issue but what caught me by surprise today is that popular frameworks have this problem, and indeed, our own code base had them as a result. Luckily, we can use regular expressions to get the job done quickly. Using CFEclipse/Eclipse, hit CTRL+H to bring up your workspace-wide search, tick the “Regular Expression” box and use the following search pattern (base regexp courtesy of Josh Knutson):

^((?!output)[^>\n\r])*<cffunction(((?!output)[^>])*)>

This regular expression should handle cases where cffunction start tag is on one line and end tag is on another, where start and end tags are on one line and Ben Nadel-style “attribute-per-line” tags broken up by newlines. Click the “replace” button and when prompted for the replace pattern, use:

$1<cffunction$2 output="false">

BEFORE you run this search and replace, save and commit your code so anything that goes sideways can be easily reverted.

Eclipse search and replace regular expression to add output=false to all cffunction tags

You can test this in a single file using the CTRL+F search and replace dialog box first as demonstrated in the above screenshot (note, the screenshot does not have the right regex).

There are a huge number of functions in popular frameworks like Coldspring 1.2, Model-Glue 2 and Transfer ORM that are missing an output tag (and a smaller number of instances where output=”true”, which should also be corrected). If you instantiate these frameworks in persistent scopes (who doesn’t?), this is a fix you’ll want to apply.

This issue may also be fixed in CF 8.0.1 cumulative hot fix 4 but it was also supposed to be fixed in CHF3. In all cases, the update is easy and is one less thing to worry about.

I have no knowledge of whether or not this exists in CF9.

[1] – How cfcomponent output=true can affect memory consumption (MxUnit.org)
[2] – Fixing a mysterious memory leak on ColdFusion (Peter Farrell)

4 Comments

  1. Josh Knutson said:

    on January 25, 2011 at 8:57 pm

    for those users that may be lazy like me, the regex for checking output=false on cfomponent is
    ^((?!output).)*<cfcomponent((?!output).)*$

    It is a really good idea to run these regular expressions on projects at least once a month or before a big release since I still come across places where people have typed out ouptut="false" or are missing it entirely. Granted that sometimes I find cases where people have type the word locla instead of local also.

  2. 3 Useful Regular Expressions » ghidinelli.com said:

    on February 8, 2011 at 1:43 pm

    [...] I posted the regexp for adding output=”false” recently, it reminded me that I had saved a number of other regular expressions for previous [...]

  3. daniel godinez said:

    on February 13, 2011 at 4:56 pm

    Hi,
    My name is Daniel. I am from Australia.
    I was hoping you could help me with this, does Cumulative Hot Fix 4 have to be applied to each CF server instance or just the main CFUSION?
    We are migrating to CF9 in late June, but I am just starting in this role and realised that the hot fix wasn’t applied to our servers and they are affected by some of these bugs.
    Regards,
    Daniel

  4. Brian said:

    on February 14, 2011 at 12:19 pm

    @Daniel – not a great place to ask that question but the quick answer is, if you are using Jrun multi-server install, you need to install it to each directory (cfusion is the default instance usually). You install it via the CFAdmin by clicking the “I” information button at the top right and then selecting the file. Hope that helps!

{ RSS feed for comments on this post}