question

SimonScott-1980 avatar image
0 Votes"
SimonScott-1980 asked SimonScott-1980 commented

Potential Memory Leak

Good morning all,

I have an Windows form based app which runs on various PC's 24/7.

However, the application over time consumes RAM and the PC will crash if not restarted manually.

My initial thoughts are to set a timer on the APP to restart after a certain period of time. However, i feel this isn't the best way to do this.

Can anyone help?

Thanks
Simon

dotnet-standard
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered SimonScott-1980 commented

the best solution is to fix the memory leak.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Bruce.

Yes i do agree!

However, i am a basic programmer and have no idea what to do!

Could you give me any pointers?

Thanks

0 Votes 0 ·
OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered SimonScott-1980 commented

However, i am a basic programmer and have no idea what to do!

Run the VS Code Analysis, it show common design failures, like missing .Dispose() calls on managed objects, which causes high memory consumption.

https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/docs/code-quality/how-to-run-code-analysis-manually-for-managed-code.md
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your reply @OlafHelper-2800

I have run the VS Code Analysis and it says it has completed but doesn't indicate any changes or recommendations!

I believe that this section of the code is where i need to add in the "dispose" method but unsure exactly how to. I did try adding proc.dispose but the memory usage still increases when the app is running.

Dim sSubString = sString.Substring(sString.LastIndexOf("|") + 1).Trim()
Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/c" & ("tzutil.exe /s " + """" + sSubString + """"))
'Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & ("tzutil.exe /s '" + sSubString + "'"))
Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
proc.StartInfo = procStartInfo
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden
proc.Start()

Thanks
Simon

0 Votes 0 ·