Hi All
We are using a custom RuntimeDataBuilder class that dynamically constructs a .NET type in-memory using Reflection.Emit to create simple property getters/setters for the information that we receive from a generic WCF DataService. The service exposes a "DataSet like" structure consisting out of 1..m DataTableDefinitions each containing 1..m DataTableColumnDefinitions. When the information is received client side, we generate the type with its property setters/getters to improve the performance and facilitate binding on our Silverlight client. All of this works fine.
My question is related to the possible memory leak associated with regenerating the type. From time to time the user can change the query parameters which may then result in more/less information coming across the wire. It therefore invalidates the previous type that we have created and I want to make sure that we are able to free up the memory used by this previous type definition. From this article on MSDN I gather that if you are using Light Weight Code Generation (LCG) the code is allocated on the managed heap which will be reclaimed by the GC when there is nothing holding a reference to it. But LCG only seems to apply to dynamic methods. My concern is for the Type with all its property getters/setters that is now not required anymore. If this is allocated on the unmanaged heap our only hope for reclaiming the memory seems to be to make sure that the type is loaded into a temporary AppDomain that we can unload when it is not required anymore.
Can somebody please confirm or highlight another way of reclaiming the memory.
Thx