Concensus on New parameters?

  • Thread starter Thread starter Larry Serflaten
  • Start date Start date
L

Larry Serflaten

Can it be known what becomes of the Pen object in a call like:

Me.CreateGraphics().DrawLine(New Pen(Color.Red), 0, 0, 30, 30)

Typically, a Pen object should be disposed, and other objects may
require more significant resources, so I wonder if the pen is left for
the GC to finalize, or are the resources released after the call is
completed?

I am thinking this is such a handy way to pass parameters that the
compiler should be smart enough to know that we don't need the
resources after the call has finished, meaning it's Dispose method
should be 'automatically' called when the method has completed.

Is there any documentation that discusses this type of situation?

LFS
 
Larry,
Typically, a Pen object should be disposed, and other objects may
require more significant resources, so I wonder if the pen is left for
the GC to finalize, or are the resources released after the call is
completed?

Left for the GC like any other object.

I am thinking this is such a handy way to pass parameters that the
compiler should be smart enough to know that we don't need the
resources after the call has finished, meaning it's Dispose method
should be 'automatically' called when the method has completed.

I don't see how the compiler could assume that. The method you're
calling could store a reference to the object for later use.



Mattias
 
* "Larry Serflaten said:
Can it be known what becomes of the Pen object in a call like:

Me.CreateGraphics().DrawLine(New Pen(Color.Red), 0, 0, 30, 30)

Typically, a Pen object should be disposed, and other objects may
require more significant resources, so I wonder if the pen is left for
the GC to finalize, or are the resources released after the call is
completed?

I am thinking this is such a handy way to pass parameters that the
compiler should be smart enough to know that we don't need the
resources after the call has finished, meaning it's Dispose method
should be 'automatically' called when the method has completed.

In your case, I would use 'Pens.Red' ;-).
 
Back
Top