Visual Studio 2022 won't release memory

Todd Lerew 60 Reputation points
2024-02-20T20:42:56.2333333+00:00

Hello everyone; I have a new issue in my project in VS2022. I recently converted my software from VS2008 to VS2022 and it has been such a problem. My project is an ERP Software System that runs a company. Since going to VS2022, I have encountered a number of issues and with some help, been able to work thru them. Here's the newest one - my project, like I said, is an ERP System that runs a company - it consists of over 400 forms, 500 crystal reports, and a SQL Database. I probably have 80-100 client computers across the country who login in and use my software. We have been on this software since 2009. Since my conversion from VS2008 to VS2022, along with the other issues, the memory of the client computers keeps building when they do certain tasks in my software, where eventually their computer will lock up. It seems when VS2022 opens and closes a windows form, it does not release the memory used for that form? This is really bad when I open a form with a crystal report. If I open a windows form with an embedded crystal reports viewer, and then load a crystal report into the viewer, the memory will spike about 1.2GIGS higher. If I print, then close the windows form, it will release about 30MEGS for the windows form, but nothing else. So if I open more crystal reports, it adds 1.2G to the memory stack, then subtracts only 30MB when the form is closed. So you can se that after about 5 or 6 crystal reports, my program locks up the client pc. I have no idea why this happening or what is going on with this. Why is this different that VS2008? What am I missing? I try to dump the resources of the form before I close it but this doesn't seem to work in VS2022. Does anyone have any ideas? Thanks, Todd

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,448 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 57,216 Reputation points
    2024-02-20T21:03:58.7466667+00:00

    There are many things that could be leaking. If your form hooks into any static events then you must explicitly unhook them before the form closes. My gut instinct is that your form isn't actually getting deleted because something has a reference to it.

    One possible culprit is CR itself. If you're interacting with the CR library then you need to ensure you're cleaning it up. Refer to their docs on how to do that properly. It is possible that the CR viewer has a memory leak as well. From what you describe it sounds like the data for a report is getting loaded but never released. Review every place you are hooking into the viewer and ensure you're cleaning those up before the form closes.

    One thing you should probably consider doing is running a memory profiler. The goal is to determine what memory is still allocated that shouldn't be and figuring out why. There are many tools available for this but a good starter tool would be the free one's provided by MS. You need to identify what objects are taking up a lot of memory and then trace back to where they came from and why they weren't cleaned up. The commercial tools may be better able to simplify this task but refer to this blog article on how to get started with the free tools.

    If you're running the VS Enterprise edition then it also has a diagnostic tool that can help. But that won't help you if you aren't running Enterprise.

    Also be sure to review all the warnings generated by the compiler and analyzers that run in the IDE. They can identify where you are not cleaning up resources properly in some cases which will help.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.