There is an article in the GDI+ FAQ that deals with this subject.
--
Bob Powell [MVP]
C#, System.Drawing
Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm
New GDI+ articles include how to use the LinearGradientBrush and
how to draw text on a reversed Y axis for graphs and charts.
" #Hai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I know that in C#, destructor is a finalize method. This means that the
> destructor is only called when the Garbage collector does it job. But the
> the GC is always does it job when the memory is full. Is there any thing
> wrong ?
>
> If it is true, now we consider GDI object (such as Image, Graphics, Pen.
> Brush or even Timer (not GDI object) ). After we use it we assign the
object
> to null:
>
> Pen p = new Pen(Color.Red);
> //....using pen here
> p = null;
>
> If the above code is in a loop (repeat about 1000 times), a 128MB memory
is
> ,certainly ,not full but the resource will run out of its capacity
(because
> none of finalization methods are called and therefore, none of pen
resources
> are free). That problem is much more seriously if the resource is timer
(we
> have only a few timer).
>
> However, the following code works smoothly in less than 1 second and there
> is no error reported by Windows
> Graphics g = CreateGraphics();
> for (int i= 0; i < 1000; i++)
> {
> Timer t = new Timer();
> t.Interval = 100;
> t.Start();
> t.Stop();
> }
>
> Where is my mistakes ? Can any one point it ?
> Thanks
>
>