Skip to content

NET5 ImageList GDI object leak #4928

@vsfeedback

Description

@vsfeedback

This 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

  1. Create a WinForms application this will default with a form called Form1.
  2. Add a second form to the Application called Form2
  3. In the Forms Designer add an ImageList to Form2 and Add any Bitmap to the ImageList
  4. 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();
    	}
  5. Open Task manger select the details tab and add GDI objects column if not already visible.
  6. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions