How to release memory in a WPF application in C#?

Asked

Viewed 72 times

1

Well I created a system in WPF and C# and every day that passes it gets bigger, I honestly had never worried about the issue of memory for small applications doesn’t make much difference, but that’s not the case.

Now I have the following situation, some people stay days with the system open and it only consumes memory until there comes a time that bursts and it closes.

Not enough quota to process this command [Memory: 739614720] em MS.Win32.UnsafeNativeMethods.PostMessage(HandleRef hwnd, WindowMessage msg, IntPtr wparam, IntPtr lparam) in System.Windows.Interop.HwndTarget.Updatewindowsettings(Boolean enableRenderTarget, Nullable`1 channelSet) in System.Windows.Interop.HwndTarget.Updatewindowpos(Intptr lParam) in System.Windows.Interop.HwndTarget.Handlemessage(Windowmessage msg, Intptr wparam, Intptr lparam) in System.Windows.Interop.HwndSource.Hwndtargetfiltermessage(Intptr hwnd, Int32 msg, Intptr wParam, Intptr lParam, Boolean& handled) in MS.Win32.HwndWrapper.Wndproc(Intptr hwnd, Int32 msg, Intptr wParam, Intptr lParam, Boolean& handled) in MS.Win32.HwndSubclass.Dispatchercallbackoperation(Object o) in System.Windows.Threading.ExceptionWrapper.Internalrealcall(Delegate callback, Object args, Int32 numArgs) in System.Windows.Threading.ExceptionWrapper.Trycatchwhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

I did some research and what I saw was for the GC to do the "cleaning" automatically, but that’s not what’s going on. I also called Dispose in some Database classes but it didn’t help much either.

I debugged the system and simulated some situations

inserir a descrição da imagem aqui

Even if I close the tab or change the service order I realized that really memory doesn’t clear.

Does anyone have any idea what I can do to improve this situation.

I caught some logs and this error happens in people who stay with the system several days open normally 2 or 3 days, it does not go beyond this because it bursts the memory kkk.

In a company of 60 employees happens about 2 or 3 times a day in all, but I would like to optimize the code, because the system will grow and this problem can be serious in the future.

I searched on memory Leak and I believe I got to the problem

https://blog.jetbrains.com/dotnet/2014/09/04/fighting-common-wpf-memory-leaks-with-dotmemory/

It seems to be related to x:Name of Radgridview, I did some tests and apparently improved the scenario but I’m still analyzing.

  • 1

    Hi Hi Hi, before you enter the world of GC, I would say analyze simple things, and with that you can use Visual Studio Profiler the memory consumption, for the experience I’ve had in the past, the simple factor that a User Control or Window is being instantiated again every time it opens it creates a memory Leak, that’s where you’ll find your problem. It may take a day or two to happen, but you create a routine that clicks on views repeatedly, for example. It can be the open and close views. But it can be objects that grow because they are not being cleaned when db queries.

  • if you can, show the code you are using that generates this excessive consumption

  • 1

    You have a memory problem. Staying with the system several days open is not a problem. You are leaving "junk" in your memory over time. https://answall.com/questions/186644/como-identificar-e-evitar-memory-leak-no-net

  • Thanks I’ll do a search in memory Leak and tips to see if I find the problem rsrs

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.