Memory leak in an managed application

V

Vinz

We use the Compact Framework on a x86 device runnning CE 6.0 (.NET Compact
Framework 2.0 SP2).

We noticed that with the folowwing application.We have a memory leak (see
Below). We also noticed that we had the exact same leak if we use a native
application and Call a CreateProcess the same way. We start the process and
close the handle of that process when the process is done.

We solved the leak in the native application by calling a closehandle on
both the Thread handle and Process handle given by CreateProcess.

It seams to me that the Process class closes the process handle but not the
main thread handle.

How am I supposed to solve this? Any suggestion?

Can someone confirm (I guess the compact framework guys) that they do or do
not call that close handle on the main thread just like it is written in the
createProcess function (only in the CE 6 version)?

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace LeakTest
{
class Program
{
static void Main(string[] args)
{
if(args.Length > 0)
{
System.Console.WriteLine("I exist "+args[0].ToString()+".");
Thread.Sleep(200);
return;
}
else
{
for (int i = 0; i < 100000; i++)
{
Process p = new Process();

p.StartInfo.FileName = "\\userdisk\\LeakTest.exe";
p.StartInfo.Arguments = i.ToString();

try
{
if (p.Start())
System.Console.WriteLine("Program started");
else
System.Console.WriteLine("Program not started");
}
catch(Exception e)
{
System.Console.WriteLine("Exception occured while
starting"+e.Message);
p.Close();
return;
}

System.Console.Write("Waiting for process to
terminate...");
try
{
p.WaitForExit();
}
catch(Exception e)
{
System.Console.WriteLine("Exception occured while
waiting" + e.Message);
p.Close();
}
System.Console.WriteLine("Done");


p.Close();
}
}
return;
}
}
}
 
V

Vinz

Hi Drew,

I did try to call dipose instead of close and also close then dispose. It is
the same behavior everytime. When my programs terminates, the memory is not
ALL given back to the OS and if I try with an infinite loop I go out of
memory.

In MSDN doc, it says on Close():Frees all the resources that are associated
with this component.

I'm not sure if I should say it but we found a solution. We created a new
class that calls a pinvoke of CreateProcess and closes all handles. This is
really anoying since we don't want to rewrite all the compact framework.

I think that there is a problem in the compact framework Process class. Our
workaround is ok but we would really like to be able to use the Process class
directly.

Thanks Drew.
 
W

Werner

Hi Vinz,

This sounds like a real bug.
If you submit a support incident, you can address this issue and have MS fix
it.
A support incident is basically payed support, but if your issue prooves to
be a bug, they will not charge you for it:).
With every Visual Studio license you get 2 or 4 support incidents for free
(depends on your license or msdn subscription). I have done this myself a few
times already and never had to pay for it. All my issues appeared to be
bugs:-(

Success
Werner

See also http://support.microsoft.com/oas
 
V

Vinz

I tried the same code on a XP machine (full .NET Framework 2.0). It seams
that the leak is also there. Can somebody try it and confirm the problem?

I think i will open a case.
 

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

Top