By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Concensus on New parameters?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2

P: n/a
* "Larry Serflaten" <se*******@usinternet.com> scripsit:
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' ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.