473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

System.Diagnostics.Process causig memory leak

Hello NG,

iam having a problem with the code block below. All what i do is to
trace processes that exited. Iam using a 5 sec timer to call the
following Method:
(wich i think is causing the leak)

private void GetRunningProcesses(){

System.Diagnostics.Process[] p =
System.Diagnostics.Process.GetProcesses();
for(int i = 0; i<p.Length ; i++){

p[i].EnableRaisingEvents = true;
p[i].Exited += new System.EventHandler(MyProcess_Exited);
}
p = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

}//end

The Method is running in a service. Onstart i call the timer to call
TimerCallbackProc in a 5 sek intervall like this:

OnStart(){
Proctimer = new System.Timers.Timer(5000);
Proctimer.Elapsed+=new
System.Timers.ElapsedEventHandler(TimerCallbackPro c);
Proctimer.Enabled=true;
}

The timer callback is triggering GetRunningProcesses()

private void TimerCallbackProc(object source,
System.Timers.ElapsedEventArgs e)
{
GetRunningProcesses();
}

There is no other code wich iam calling in the service only the
methods you see, but still the application is growing and not freeing
any memory!

Can anybody tell me what iam doing wrong? As i said the code is
running in a service and keeps growing in memory usage :(

thanks for advice

regards Sebastian
Nov 16 '05 #1
2 6402
Bob
Are you sure you have a leak. .NET does garbage collection
very late. Also, what is the purpose of:
On 2-Dec-2004, se*************@dregis.com (Sebastian Sosna) wrote:
p[i].EnableRaisingEvents = true;
p[i].Exited += new System.EventHandler(MyProcess_Exited);


Seems to me you're stacking up handlers here.
Nov 16 '05 #2
Hello Bob,

thanks for reply. Ehhm yes your right GC is collecting, but too late!
I ran 2 days the app looking at it right now being stable at 14 mb.
But the highest peeks where about 80 mb!!!! Thats too much.
How can I force the GC to collect not referenced events lets say every
hour? Is that possible?

Thanks!

Regards
Sebastian
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: T | last post by:
How do you catch the "Exited" event when a process is terminated. In the following code sample the "myProcess_Exited" event is never called. Any help would be appreciated. using System; using...
2
by: Ben Tan | last post by:
hi, i'm trying to launch a browser with Diagnostics.Process.Start("http://somesite.com?a=b&c=d"); the problem is that the URL for the site is always appended with a "/" so when the browser...
1
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I...
35
by: Alex Martelli | last post by:
Having fixed a memory leak (not the leak of a Python reference, some other stuff I wasn't properly freeing in certain cases) in a C-coded extension I maintain, I need a way to test that the leak is...
4
by: ali.jan | last post by:
Hi, It is trivial to load an assembly in a new Application Domain. Is there any way of loading an assembly in a new process? I tried using the Process class like this: Process p = new...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
0
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine....
2
by: Macca | last post by:
Hi, I would like to get the memory usage of the process my app is running in so i can monitor levels of memory during runtime. I've been told I can use the System.Diagnostics.Process class to do...
3
by: Bali | last post by:
Hi I have an ASP.NET application. I am on the server side and trying to start an application which is on the server. The process gets started(can be seen in the Task Manager) but doesn't do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.