?
Solved

Need to unload an external assembly that is causing memory leak

Posted on 2012-04-01
2
Medium Priority
?
401 Views
Last Modified: 2012-04-02
Hello,
I am maintaining a fax server Windows service written in C#. The service references a compiled external .NET library for imaging functions.
In several production environments, every few days, the imaging component starts to throw exceptions claiming that memory is corrupt, and after that it stops working altogether, crashing the service.
The component's developers are no help because this is an older version of the component which isn't supported, and currently I cannot upgrade. Also, this was tested in several production environments and occurs in all of them, so it is unlikely that this is really corrupted memory. From the steady increase in memory consumption I assume this is a memory leak on their part. Restarting the service always solves the problem.
I would like to unload the reference to the external component and re-load it after each call. I prefer this to restarting the service automatically on a schedule. However, I have tried to dynamically load the component using Assembly.LoadFrom and using reflection, but the component throws generalized meaningless exceptions whenever I invoke any methods.
Can anyone suggest how to do this?
Thanks!
0
Comment
Question by:rumblefish978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 1600 total points
ID: 37794940
One solution is to load the assembly in a separate AppDomain rather than the main domain, unloading the AppDomian would reclaim resources - however that too does not work very well with unmanaged leaks for example. The referenced components may be using OS resources or native heap and such leaks can not be prevented even using AppDomain.

The best solution is to put the component in a separate (surrogate) exe process that remotes or use WCF if you wish. Remoting is pretty easy to setup and you may even do the hosting part without coding (just config). That exe can be recycled for each call and unloading a process will reclaim even leaked resources (at least most of them).
0
 

Author Closing Comment

by:rumblefish978
ID: 37794951
Thanks for the short but thorough explanation. I will implement it the way you said.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question