question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NET5 ImageList GDI object leak

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kirsan31commented, Jun 1, 2021

Will be in 5.0.8.

1reaction
Zheng-Li01commented, May 27, 2021

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. VerifiedIssue4928

Read more comments on GitHub >

github_iconTop Results From Across the Web

GDI object leak and overflow when TImageList is on a frame
We have DeLeaker purchased and is showing no memory leaks. ... If I completely remove the ImageList, GDI object count stays top 2500....
Read more >
How to debug GDI Object Leaks?
Our issue with our app (and the GDI object leak) was that we were using a static object and binding to it. There...
Read more >
Resource Leaks: Detecting, Locating, and Repairing Your ...
As bugs go, leaks are some of the most difficult to find, especially when they occur in graphics device interface (GDI) objects and...
Read more >
GDI/User Object Leak Tracking – The Easy Way - Alois Kraus
One of the most complex issues are User/GDI object leaks because they are nearly invisible in memory dumps. Microsoft does not want us...
Read more >
gitlog.txt - GitHub
... +1000 dmex : Fix imagelist assert from token window [64b54752] 2021-08-31 ... 06:29:22 +1000 Justin Gottula : Fix a thread handle leak...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found