I have been chasing a bug in a VB.NET Windows Forms application today. The error log was filled with Win32Exception Error creating window handle. Digging in the usage log I loacted the following code.
propertyHolder is a Control.
So whats the memory leak here?
radioButton.FindForm.Controls.Remove(control), since we remove the control from the container(Form). We now inherit the responsibility to clean up.
So a non leaking version would be.
So remember to dispose a control when you dynamically remove it from its container.
The application also had a while loop that in some conditions never exited, and called the above method.