IgnaceMaes / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
2.84k stars 831 forks source link

materialCheckbox memory leak #95

Open MikeGWem opened 8 years ago

MikeGWem commented 8 years ago

I noticed that the process memory increased steadily in response to a click setting a Checkbox state to checked. That was substantially relieved by shifting the code in DrawCheckMarkBitmap() to the main onPaint() method and disposing of the graphics and bitmap objects - something like:

` var checkMark = new Bitmap(CHECKBOX_SIZE, CHECKBOX_SIZE); using (var gi = Graphics.FromImage(checkMark)) { // clear everything, transparent gi.Clear(Color.Transparent);

                // draw the checkmark lines
                using (var cmpen = new Pen(Parent.BackColor, 2))
                {
                    gi.DrawLines(cmpen, CHECKMARK_LINE);
                }
            }
            g.DrawImageUnscaledAndClipped(checkMark, checkMarkLineFill);
            checkMark.Dispose();
            //g.DrawImageUnscaledAndClipped(DrawCheckMarkBitmap(), checkMarkLineFill);

` However a small memory increase persists with continued clicking on a Checkbox. If I spot the source I will add to this.

Dutchs commented 7 years ago

This seems more like a case of the GarbageCollector not feeling like cleaning up (in a timely manner) rather than a memory leak, but i agree. any IDisposables that are short-lived should be wrapped in a using block ie: Pen, Brush, Bitmap, Graphics, GraphicsPath, StringFormat etc