In our application, we need to call functions from external assembly. Below is what we have already done?
1 Please note that user can create his own assemblies and can call any static public functions in those assemblies from our application.
2 Once the user has created his assembly, he let our application know which function in that assembly is to be called.
3 We load user specified assembly in a separate application domain.
4 We determine if the function that user wants to execute, actually exists in that assembly. (For this we use reflection to get complete information of the assembly).
5 Then we create parameters that are to be passed to the function in external assembly. For preparing parameters we are using a class Arg derived from interface MarshalByRefObject as below:
internal abstract class Arg : MarshalByRefObject
So Arg's object will represent parameters to be passed.
6 Now the problem comes. More the parameter we pass to a function in external assembly, more the memory leaks are there. If we call a function several times, memory leaks grows proportionally (even when that separate app-domain is unloaded).
7 So the reason of these memory leaks is that parameters (represented by Arg class derived from MarshalByRefObject) are not being collected by Garbage Collector (even when called explicitly).
8 Any comment on how can we free objects of Arg (created for passing parameters)? Or is there something that we should take extreme care about while doing stuff like this?