Beware of the UnUnloadable IL!

Today an interesting thread was started on the DOT-NET CLR mailing list. The topic: a possible memory leak can occur when you are not careful with XSL transformations or compiled regular expressions. The reason for these memory leaks is that the CLR is generating IL behind the scenes and generated IL cannot be unloaded from an AppDomain unless the complete AppDomain is unloaded. Garbage Collection (GC) is not fixing this. The XSL transformations which will cause trouble are the ones which have to deal with XSL stylesheets with JScript embedded. The JScript is compiled into IL and as said, this will never be unloaded.

Visit the start message and all its follow-ups by clicking here.

I wasn't aware of this (as you can read in the thread) and will now rework my LR(1) parser to use cached static compiled regular expressions to avoid this memory leak. I thought GC would take care of the compiled regular expression but this is not the case. Since the parser parses UBB code and HTML in a webapplication, it is instantiated on every parse request, which will then cause the generation of a new set of compiled regular expressions, which will never be unloaded. Who would have thought of that!

Ryan Heath mentioned an article about this in the MSDN: [here]

Happy Patching ;)

No Comments