I have a problem with a possible memory leak in my WinForms app. I finally was able to figure this out and reproduce by doing the floowing.
Add a FlowLayoutPanel to a form and have a process that adds (multiple) Buttons at runtime. Then i have a method that is called from an event (button click) that removes the controls like this:
Code Snippet
Me.FlowLayoutPanel1.Controls.Clear()
then call the method to re-add them back using:
Code Snippet
Me.FlowLayoutPanel1.Controls.Add(New Button...)
This works except for the Mem Usage on the machine. This goes thru the roof after loading 30 controls over and over again.
I have tried all of the following without luck:
Code Snippet
For Each ctrl As Control In Me.FlowLayoutPanel1.Controls ctrl.Dispose()
ctrl = Nothing
Next
GC.Collect()
Me.FlowLayoutPanel1.Controls.Clear()
Any ideas
Thanks in advanced.