How to release the occupied memory

2020-01-29 19:11发布

I have a main window in my project, and numerous other child widows inside the main.
I have noticed that. When I open the main window occupies 1500K of memory, when open one child window then adds in occupied memory 6000K.
When I open the second window doing the same. When I close the two child windows the occupied memory is not released.
So What I want is to release the occupied memory when ever I close child windows.
How I can do that?
Please advice me with some code example in vb.net if it is possible.
This problem often sawing in the computers on the Local NET not in my computer (developer computer which has the SQL server on it).

7条回答
Melony?
2楼-- · 2020-01-29 19:49

You can use one of memory profilers available, e.g. ANTS Memory Profiler (take a look to Using ANTS Memory Profiler to track down a memory leak in a WinForms application). You can also use WinDbg but without experience it will be more complicated than specialized tool.

One of common "memory leak" reason is adding "external" event handler to form (e.g. to static or long living object), and not remove it on form destroy, so GC "thinks" you have reference to form and not collect its data.

Why and How to avoid Event Handler memory leaks ?

.NET Memory Leak Case Study: The Event Handlers That Made The Memory Baloon

Fundamentals of Garbage Collection

Dispose, Finalization, and Resource Management

How to identify memory leaks in the common language runtime

How to detect and avoid memory and resources leaks in .NET applications

查看更多
登录 后发表回答