Monday, February 06, 2006

Leaking an assembly everytime you create an object

One would think that it is very hard thing to dynamically create assemblies, load them and leak them. Not to worry, dotnet makes it easy for you via the XmlSerializer class :).

Except for a couple of constructors, all of them leak an assembly per XmlSerializer object class created (which would normally be more or less every time you serialize/deser in ur WS layer)

More info over here

To increase performance, the XML serialization infrastructure dynamically generates assemblies to serialize and deserialize specified types. The infrastructure finds and reuses those assemblies. This behavior occurs only when using the following constructors:

System.Xml.Serialization.XmlSerializer(Type)
System.Xml.Serialization.XmlSerializer(Type,String)

If you use any of the other constructors, multiple versions of the same assembly are generated and never unloaded, resulting in a memory leak and poor performance.

Moral of the story: Read msdn2 documentation.

Friday, February 03, 2006

Interesting puzzles - 7

You have an building with N floors and 2 identical glass balls. You can drop a ball from any floor. Determine minimum floor from which either of the balls will break in the least number of drop attempts.