In Microsoft ASP.NET, the memory usage increases unexpectedly when you create several XmlSerializer objects.
This problem occurs because an assembly that contains Microsoft intermediate language (MSIL) is created and loaded into memory when you create an XmlSerializer object. You cannot unload the assembly without unloading the application domain that it resides in. Therefore, when you create several XmlSerializer objects, you may notice unexpectedly high memory usage.
For example, if you use the following constructor to create several XmlSerializer objects, a new dynamic assembly is created every time:
public void XmlSerializer( Type t, Type extraTypes)
To work around this problem of re-creating dynamic assemblies, use one of the following methods:
Create one instance of the XmlSerializer class, and put that instance in the cache by using the caching APIs. For example, for a .dll file that is named HighSchool, the following code caches one instance of the XmlSerializer class: