How to create giant memory leaks with XmlSerializer
In this post, Tess describes how using repeatedly calling:
XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder), new XmlRootAttribute(""));
leaks a temporary assembly on each call. Ouch! Some of the other constructors cache the assemblies, but this one doesn't.
I was really surprised the first time I realized that temporary assemblies were getting generated. The perf hit is pretty huge the first time you do this. This is not a huge deal in a server app, but in a client app, this slows does launch time. In .NET 2.0, you can use sgen.exe to generate the assembly at build time so it doesn't have to happen at runtime.