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;
}
}
}
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;
}
}
}