Problem with complex form. After closing the form, the RAM will not be empty.

m145854741211444

New member
Joined
May 10, 2021
Messages
2
Programming Experience
5-10
Hello to all.
I have a complicated Windows C# form, when users want to execute that form, it takes up about 1.2 GB of ram.
After closing the form, the ROM will not be empty. this form opened inside of the DEVExpress form. and if user wants to open that form again, this time ram will takes 2.4 Gig of ram And gradually the memory fills up and the memory shortage error is displayed.
If it is passable please help to solve this problem.
how I can clear the RAM when form is closed.
I used Dispose Method. but it does not works.
Best regards.
 

Attachments

  • Capture.PNG
    Capture.PNG
    11.9 KB · Views: 29
Last edited:
You should do a bit of reading on how .NET manages memory. Broadly speaking, it allocates memory when it's required and deallocates memory when it can. In all but very rare cases, you don't need to worry about that deallocation yourself, but you do need to manage your objects properly in order ensure that .NET can do what it does efficiently. That means ensuring that you don't maintain references to objects that you no longer need to use and that you dispose objects that support it when you're done with them. You are probably not doing one or both of those things, meaning that .NET cannot deallocate the memory occupied by that form or at least not do so in a timely manner. It's impossible to say for sure though, as you haven't really given us any information to work with.

I strongly suggest that you do some reading on this topic, do what you can to improve your code and then post back with more information if you still have an issue. That said, one thing you might do by way of test is to minimise your app and activate some other app and see whether the memory gets cleaned up. If it doesn't then you're definitely doing something wrong. If it does then it may be that you just have to .NET clean it up when it needs to. If you get no OutOfMemoryException then you don't necessarily have an issue.

Having said all that, I have to question the wisdom of a form that uses that much memory. Maybe there's a good reason for it but I would certainly consider whether your design could be improved.
 
For the record, disposing an object has no direct effect on memory. Disposing an object releases the managed and unmanaged resources that are held by an object. Memory does not qualify as a resource in this context. Unmanaged resources are things like file and window handles. Unmanaged resources are .NET objects that themselves support disposal. Disposal may also involve setting a field to null if that field refers to an object that occupies a lot of memory. What these actions do is reduce the number of actions required by the system before it can actually deallocate the memory occupied by an object, meaning that that memory can be released back to the system sooner.
 
ROFL! Nowhere in your original post did you mention that you were using Entity Framework. If you had mentioned it, and @Sheepings were still active on this forum, he would have pointed you in that direction right away as something to look at because of his multiple memory leak experiences with EF.
 
Back
Top Bottom