how to unload assembly from application and free the memory it held?

  • Thread starter Thread starter navyliu
  • Start date Start date
N

navyliu

I use plugin controls in my application,but i find i can't free the memory
the assembly held.
please help me.
 
hi Marc,thank you for your answer.
I have read the articles,but I think they can't solve my problem.
The solution for unloading Assembly follows following steps:
1.Create a new AppDomain;
2.In the new AppDomain,Load some assembly;
3.Create an Instance of some Class and send the instance outside the
appdomain for using through Remoting.

the problem is step 3.
I want to use these Instances(usually are UserControls) in my plugable
framework. I have to pass object between AppDomains.
The only way to pass object between AppDomain is remoting.
That's to say all my plug - in must inhert MarshalByRefObject.
I have tested. The UserControl can pass to the framework,
but it can be add into the Container. the exception is following:
"Remoting can't find the field parent from Type
System.Windows.Forms.Control".
?????????"System.Windows.Forms.Control"?????"parent"?

If you want to discuss this problem directly,you can add my msn
:[email protected].
Best regards.
Navyliu
 
Perhaps do it the other way around; in the new app-domain, load
whatever assemblies your UI needs, and have the new form load in the
new app-domain. Aside from working, this also creates a sandbox and
prevents malformed plugins from either attacking or breaking your UI.
To interact with the new form, I would create a class :
MarshalByRefObject which exposes the required methods; the instance
would sit in the new app-domain, but you can pass the reference via
remoting back to the original AppDomain; now you should be able to call
myProxyClassInstance.ShowForm() or whatever; the method is remoted to
the new AppDomain, where your class talks to the UI to call .Show() [or
similar].

When you are done, you simply can the AppDomain (preferably gracefully
Dispose()ing the objects first), and hey presto: gone.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top