Memory leak?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Suikwan
    New Member
    • Feb 2007
    • 11

    Memory leak?

    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.

    Code:
    Imports System.Diagnostics
    Imports System.IO
    Public Class Form1
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e _
    As System.EventArgs) Handles Timer1.Tick
            Execute()
        End Sub
    
        Private Sub Execute()
            Dim PrcsEncode As Process()
            Dim TodayDateTime As Date = Now()
    
            PrcsEncode = Process.GetProcessesByName("Encode")
    
            If PrcsEncode.Length = 1 Then
                PrcsEncode = Nothing
                Exit Sub
            End If
    
            If PrcsEncode.Length = 0 Then
                PrcsEncode = Nothing
                
                File.AppendAllText("C:\documents and settings\user\ _
                    desktop\ProcessesLog.txt", TodayDateTime & " - The _
                    application was not running." & vbCrLf & vbCrLf)
                
                 Shell("C:\DVR\DVR.exe", , True, 7000)
            End If
        End Sub
    End Class
    Last edited by Suikwan; Feb 18 '07, 01:18 AM. Reason: Title not clear
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    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.

    Comment

    • Suikwan
      New Member
      • Feb 2007
      • 11

      #3
      Originally posted by willakawill
      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 GetProcessesByN ame method checks for the Encode process which is related to the dvr.exe application. Shell is only called if Encode is not found running.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by Suikwan
        Thanks for the input. The GetProcessesByN ame 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 GetProcessByNam e 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.

        Comment

        • Suikwan
          New Member
          • Feb 2007
          • 11

          #5
          Originally posted by Killer42
          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 GetProcessByNam e 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.Diagnost ics.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.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by Suikwan
            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.Diagnost ics.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 GetProcessByNam e, 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".

            Comment

            • Suikwan
              New Member
              • Feb 2007
              • 11

              #7
              Originally posted by Killer42
              Yeah, the restart would definitely be a last resort. Good luck on tracking down the leak.

              Not being familiar myself with the GetProcessByNam e, 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 GetProcessByNam e method. I'll keep my eye on it for the next few days. Thanks for taking the time to check it out.

              Comment

              Working...