473,406 Members | 2,549 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,406 software developers and data experts.

Memory leak?

11
This app is set to check for a particular process every 3 minutes. Seems there is a memory leak somewhere becuse it keeps using more memory. I would appreciate if someone would check to see how this can be fixed. This is running under WinXP Pro SP2, .net Framework 3.0, The code is below.

Expand|Select|Wrap|Line Numbers
  1. Imports System.Diagnostics
  2. Imports System.IO
  3. Public Class Form1
  4.  
  5.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e _
  6. As System.EventArgs) Handles Timer1.Tick
  7.         Execute()
  8.     End Sub
  9.  
  10.     Private Sub Execute()
  11.         Dim PrcsEncode As Process()
  12.         Dim TodayDateTime As Date = Now()
  13.  
  14.         PrcsEncode = Process.GetProcessesByName("Encode")
  15.  
  16.         If PrcsEncode.Length = 1 Then
  17.             PrcsEncode = Nothing
  18.             Exit Sub
  19.         End If
  20.  
  21.         If PrcsEncode.Length = 0 Then
  22.             PrcsEncode = Nothing
  23.  
  24.             File.AppendAllText("C:\documents and settings\user\ _
  25.                 desktop\ProcessesLog.txt", TodayDateTime & " - The _
  26.                 application was not running." & vbCrLf & vbCrLf)
  27.  
  28.              Shell("C:\DVR\DVR.exe", , True, 7000)
  29.         End If
  30.     End Sub
  31. End Class
Feb 18 '07 #1
6 2092
willakawill
1,646 1GB
Hi. Looks like you are calling Shell each time which could significantly deplete resources. Perhaps you could test if the app is already running before calling it.
Feb 19 '07 #2
Suikwan
11
Hi. Looks like you are calling Shell each time which could significantly deplete resources. Perhaps you could test if the app is already running before calling it.
Thanks for the input. The GetProcessesByName method checks for the Encode process which is related to the dvr.exe application. Shell is only called if Encode is not found running.
Feb 19 '07 #3
Killer42
8,435 Expert 8TB
Thanks for the input. The GetProcessesByName method checks for the Encode process which is related to the dvr.exe application. Shell is only called if Encode is not found running.
Perhaps a simplistic suggestions, but what about if you were to do the equivalent of Run periodically, to restart your application? If you can't find a more elegant way to get rid of the memory leak, this might be worth considering.

Also, do you know for sure that the whole GetProcessByName and conditional Shell business actually works as intended? When debugging, it's always a good idea to assume that pretty much anything could be wrong until proven, even if it doesn't seem possible.
Feb 19 '07 #4
Suikwan
11
Perhaps a simplistic suggestions, but what about if you were to do the equivalent of Run periodically, to restart your application? If you can't find a more elegant way to get rid of the memory leak, this might be worth considering.

Also, do you know for sure that the whole GetProcessByName and conditional Shell business actually works as intended? When debugging, it's always a good idea to assume that pretty much anything could be wrong until proven, even if it doesn't seem possible.
What exactly do you mean by works as intended? Based on my testing, if the process is found to be running, the value returned is an array with a length value of one (1); something along the lines of System.Diagnostics.something (Encode). If the process is not running, the value of the length property is zero and the IF statement is not executed. I also tested by checking for running instances of notepad. The results were consistent. I guess if I can't figure it out, then I'll go with your suggestion. Thanks for your ideas.
Feb 19 '07 #5
Killer42
8,435 Expert 8TB
What exactly do you mean by works as intended? Based on my testing, if the process is found to be running, the value returned is an array with a length value of one (1); something along the lines of System.Diagnostics.something (Encode). If the process is not running, the value of the length property is zero and the IF statement is not executed. I also tested by checking for running instances of notepad. The results were consistent. I guess if I can't figure it out, then I'll go with your suggestion. Thanks for your ideas.
Yeah, the restart would definitely be a last resort. Good luck on tracking down the leak.

Not being familiar myself with the GetProcessByName, I just wanted to be sure you had investigated that area. It sounds as though you have. (Please don’t be insulted if I ask what sound like really obvious things - you'd be amazed at the obvious things which are overlooked sometimes.)

One other question - is this the entirety of the program? I'm, just wondering whether there might be something unexpected happening elsewhere in the code which is producing the memory leak.

Oh, and just out of curiosity - how serious is the leak? Depending on the answer to that, perhaps you can just live with it (even though it might be an unpalatable answer). Or if you do end up having to take the restart route, you might be able to just do it every once in a while (Eg. once a day), and not every time you "loop".
Feb 19 '07 #6
Suikwan
11
Yeah, the restart would definitely be a last resort. Good luck on tracking down the leak.

Not being familiar myself with the GetProcessByName, I just wanted to be sure you had investigated that area. It sounds as though you have. (Please don’t be insulted if I ask what sound like really obvious things - you'd be amazed at the obvious things which are overlooked sometimes.)

One other question - is this the entirety of the program? I'm, just wondering whether there might be something unexpected happening elsewhere in the code which is producing the memory leak.

Oh, and just out of curiosity - how serious is the leak? Depending on the answer to that, perhaps you can just live with it (even though it might be an unpalatable answer). Or if you do end up having to take the restart route, you might be able to just do it every once in a while (Eg. once a day), and not every time you "loop".
No offense taken. I'm actually just starting out in the world of VB. Any and all feedback is welcome. This actually is the entire code. The leak is actually not major. Just before checking for new posts on this thread, I decided to check the memory consumption of the process. As I was looking at it, the consumption dropped by 120K (then it went up 124K :-( ). It actually looks like it has stabilized. Im sure there's gotta be something more to the GetProcessByName method. I'll keep my eye on it for the next few days. Thanks for taking the time to check it out.
Feb 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
4
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
7
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.