You need to dispose your GDI+ objects

Mar 11, 2011 at 11:55 PM

Hello,

 

I like this library very much.

 

It would be perfect if you dispose of objects as soon as those are not needed. For instance:

 

            GraphicsPath path = new GraphicsPath();
	        path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);

	        for(int i=1; i<=m_nThickness; ++i)
	        {
	            Pen pen = new Pen(m_clrOutline,i);
	            pen.LineJoin=LineJoin.Round;
	            graphics.DrawPath(pen, path);
            }

            if (m_bClrText)
            {
                SolidBrush brush = new SolidBrush(m_clrText);
                graphics.FillPath(brush, path);
            }
            else
                graphics.FillPath(m_brushText, path);

	        return true;

You must change to:

 

            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);

                for (int i = 1; i <= m_nThickness; ++i)
                {
                    using (Pen pen = new Pen(m_clrOutline, i))
                    {
                        pen.LineJoin = LineJoin.Round;
                        graphics.DrawPath(pen, path);
                    }
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
                else
                    graphics.FillPath(m_brushText, path);
            }

	        return true;

Additionally, you must dispose class level GDI+ objects like this in TextGlowStrategy:

 

protected System.Drawing.Brush m_brushText;

 

Regards

 

Coordinator
Mar 13, 2011 at 2:17 PM

Hi luisarvayo,

Thanks for the heads up! :)

Your suggestion and IDisposable is implemented.

Mar 17, 2011 at 7:49 PM

Thank you very much....The best outline library I have seen....