Home > Mobile >  Application uses over 1GB of RAM on startup
Application uses over 1GB of RAM on startup

Time:04-23

I've been working on this application for a while now and it's nearly finished so I decided to start fixing some stuff like the high memory usage.

I'm using Visual Studio 2022 and it's .NET Framwork 4.8 C# Form application. On the form I have a few page controls each with 2-5 tabs. I have a few split panel containers and all of them have buttons, labels and text boxes. I have minimal variables declared globally (6 in total), I tried declaring all variables locally. I have 1 extra class.

On startup, the Diagnostics tool shows that the application is using 1,2GB of RAM. In task manager, it also shows it's using around 1,2GB of RAM. I've gotten this down to 550G using GC.Collect(). Is there a way I can still lower the RAM usage or is it normal? If I didn't give enough information let me know and I'll give what I can.

Edit: Thanks to Juanjo, Joe Sewell and Hans Passant the problem has been solved.

I have hundreds of disposable components. Haven't done all of them but that would get me down to 550MB ish RAM usage. I did have a small database but it wasn't being connected at the start of the program. The last problem that made the RAM go from 550MB to 29MB was a few images inside an image list I had that wasn't used. Thanks to you three for the help, from 1,2GB to 29MB.

CodePudding user response:

This can be anything. Without the project and debugging it is hard to know. Nontheless, GC.Collect() bringing it down to half, knowing that there are very few cases where you need to call GC.Collect() makes me to suspect that you are using IDisposable components and you are not calling Dispose().

Look at some of the objects you are using if they have the Dispose() method and if they do use the using pattern for C# to dispose those objects when you are done with them.

I hope it helps. Again without the project it is hard to know.

  • Related