Advertisement

12.17.2007 at 04:37AM PST, ID: 23027706
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Memory leak like behavior

Asked by ChristophMurczek in Microsoft Visual C#.Net, Visual Studio, .NET Framework 2.x

Tags: , ,

Hi experts,
I have a memory leak like problem with one of my apps. The snippet shows a WindowsForms base PoC of my WindowsService I use to find the source of the problem. It basically goes like this:
 *) create a COM object
 *) connect to server and log on
 *) call a method to get another COM object (returns an interface) and register for events of that object
 *) call a method of the second object to get a third COM object to work with

In the event handler
 *) check the type of event
 *) depending on the state do some action

As you might have guessed, everything that is preceded by "SDK" is an interop object. The problem is that for some reason my app uses more and more memory (app. 500kB per 30 min). It got better ( by app. a factor of 3) when I moved the scope of the Agent and AgentBase object from the event handler to the class, but it still leaks. I would have expected the GC to collect the managed and unmanaged object when calling Marshal.FinalReleaseComObject(object) but appearantly it doesn't!

The interop assembly I use to access the COM based SDK is created via TlbImp.exe. I also tried referencing directly from VS, but it makes no difference. The COM SDK is developed by an external company. They wouldn't provide an interop assembly. I think I'm starting to see why...  ;-)

Any ideas what I can do? I don't want to go into re-writing the interop layer since this would cause a major delay for my customer.

Thx in advance,
ChristophStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
SDK.InteropObjectClass myInteropObject;
SDK.IOtherComObject myOtherComObject;
SDK.IAgent2 myAgent;
SDK.IMediaBase myAgentBase;
 
public Form1()
{
     InitializeComponent();
 
     myInteropObject = new SDK.InteropObjectClass();
     myInteropObject.Initialize(serveraddress, localport);
     myInteropObject.Logon(user, password);
     myOtherComObject = InteropObject.GetOtherObject() as IOtherComObject;
     myOtherComObject.EventOccurred += new SDK._IOtherComObjectEvents_EventOccurredEventHandler(myOtherComObject_EventOccurred);
     myAgent = myOtherComObject.NewAgent() as SDK.IAgent2;
}
 
void myOtherComObject_EventOccurred(SDK.ComEvent ComEvent)
{
     switch (ComEvent.Code)
     {
          case ComEventCode_AgentStatus:
          {
                SDK.AgentStatusEvent myAgentStatusEvent = ComEvent as SDK.AgentStatusEvent;
 
                myAgent.Key = myAgentKey;
                myAgentBase = myAgent as SDK.MediaBase;
                myMediaManager.Query(ref myAgentBase);
                System.Threading.Thread.Sleep(500);
                switch (myAgentStatusEvent.State)
                {
                     case SDK.enStates.State_Available:
                      {
                             myAgent.Unavailable(0);
                             break;
                      }
                      case SDK.enACDStates.ACDState_Unavailable:
                      {
                             myAgent.Available();
                             break;
                      }
                }
                RefCount = Marshal.FinalReleaseComObject(myAgentStatusEvent);
                break;
          }
     }
     RefCount = Marshal.FinalReleaseComObject(ComEvent);
}
 
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
     myOtherComObject.EventOccurred -= new SDK._IOtherComObjectEvents_EventOccurredEventHandler(myOtherComObject_EventOccurred);
 
     RefCount = Marshal.FinalReleaseComObject(myAgentBase);
     RefCount = Marshal.FinalReleaseComObject(myAgent);
     RefCount = Marshal.ReleaseComObject(myOtherComObject);
     RefCount = Marshal.ReleaseComObject(myInteropObject);
}
[+][-]12.17.2007 at 04:48AM PST, ID: 20484336

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.17.2007 at 05:06AM PST, ID: 20484424

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.19.2007 at 07:16AM PST, ID: 20500070

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2007 at 09:26AM PST, ID: 20501174

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, Visual Studio, .NET Framework 2.x
Tags: memory, interop, leak
Sign Up Now!
Solution Provided By: ChristophMurczek
Participating Experts: 2
Solution Grade: B
 
 
[+][-]01.04.2008 at 04:14AM PST, ID: 20581357

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628