Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is This Problem Called Memory Leak? My Application include 5 Different Form. I Showing One of Them by Using this Code :

Form2 frm2 = new Form2();
frm2.ShowDlialog();
Form2 Includes : Buttons, TextBox, Lables, Listbox to Add Items Into the ListBox.

When frm2 Appears, It Get 1MB Memory (Based on Task Manager). After Closing Form2, The Memory Still High And it Does not Decrease. If I Call frm2.ShowDlialog() For Multiple Time, Application Memory Increased Every Time.

What I have tried:

I Searched in Google and tried :

Number 1 :

Form2 frm2 = new Form2();
frm2.ShowDlialog();
frm2.Dispose();


Number 2 : (in Form2_FormClosing)

GC.Collect();



Number 3 :
I saw articles that talking about this :

Quote:
The first place to look for leaks is in event-handling rather than missing Dispose() calls. Say your container (the parent form) loads a child form and adds a handler for an event of that child form (ChildForm.CloseMe).

If the child form is intended to be cleared from memory then this event handler must be removed before it is a candidate for garbage collection.


Note : I'm using ADO.NET in Form2_Load events. (Software Based on CRUD)

Can anyone help me?
Posted
Updated 12-Jul-22 12:58pm
v2
Comments
PIEBALDconsult 12-Jul-22 20:52pm    
And don't forget frm2 = null
Member 15704684 13-Jul-22 3:58am    
Not works.

1 solution

Task Manager is lying to you.

You're seeing the memory that's RESERVED for your application, not how much it's actually using. When you dispose objects or free up any memory used, that memory goes back into the .NET heap it's maintaining for your app. It does NOT get returned back to Windows, which is what Task Manager is showing you.

If Windows needs memory returned to it, the .NET CLR will happily return whatever it can and grab new blocks of memory from Windows when needed.

If you want to see how much memory your app is really using, open up PerfMon and look at setting up appropriate memory counters for whatever you need to see.
 
Share this answer
 
v2
Comments
Member 15704684 13-Jul-22 4:10am    
Thank you very much Dave.
I used ANTS Memory Profiler.
I take a Snapshot and Shows me :

93% Unmanaged Memory and System.Object get high memory and AANTS Said that I need Unregister / Unsubscribe the Object. What should id do ?
Dave Kreskowiak 13-Jul-22 9:27am    
I don't use ANTS. I have no idea what it's talking about, nor do I have any idea what your Form2 is doing, creating, or holding onto, if anything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900