NET5 ImageList GDI object leak
See original GitHub issueThis issue has been moved from a ticket on Developer Community.
In NET5 any Windows Form that contains a System.Windows.Forms.ImageList that is populated from a ((System.Windows.Forms.ImageListStreamer)(resources. GetObject("imageList1.ImageStream")));
Leak GDI objects that are never released by the Garbage Collector, NOT an issue in NET Core 3.1, I have tested in NET6 Preview 3 and it is sill an issue.
Steps to reproduce
- Create a WinForms application this will default with a form called Form1.
- Add a second form to the Application called Form2
- In the Forms Designer add an ImageList to Form2 and Add any Bitmap to the ImageList
- Add Two buttons to Form1, one to Open Form2 and Open to Garbage Collect
private void button1_Click(object sender, EventArgs e) { GC. Collect(); } private void button2_Click(object sender, EventArgs e) { Form2 oForm = new Form2(); oForm.Show(); }
- Open Task manger select the details tab and add GDI objects column if not already visible.
- Run the application and Click Button 2 to open Form2 then close Form2 click Button 1 to garbage collect and you will see GDI object have increased. repeat this and you will see the GDI object increaing with every open and close of Form2
Attached is a sample Solution with the Project reproduced in it.
Original Comments
Feedback Bot on 5/17/2021, 10:23 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
S Myczko on 5/17/2021, 05:30 PM:
Looking at this in more detail it appears the the Dispose is never called on the this.imageList1.ImageStream, if I keep a reference to that object and call Dispose() my self it leak goes away, but this does required a change to the Forms Designer code.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
this.oImageStream.Dispose();
}
base.Dispose(disposing);
}
Original Solutions
(no solutions)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Will be in 5.0.8.
Verified the issue with latest 6.0.0-preview.5.21275.7, the issue has been fixed that “GDI objects” don’t increase as expected.