To be fair.. Not disposing of some objects is perfectly ok because the CG
will get 'em in the end. Often though, and this is particularly true for
GDI+ graphics, a good preemptive Dispose is good practice as can be forcing
GC.
A lot of MSDN examples don't include the dispose because they don't need to
confuse the issue with such trivialities in a 5 line example. For the
purpose of that example this is fine.
The technique will come back to bite you later however and it's necessary to
be aware of the implications of disposing or not.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Dennis" <(E-Mail Removed)> wrote in message
news:7B6E7173-3D97-423E-AC11-(E-Mail Removed)...
> What! Microsoft Wrong...I thought they were perfect!
>
> "Bob Powell [MVP]" wrote:
>
>> >>lots of examples in MDSN.
>>
>> Yes.. sloppy lazy and often wrong..
>>
>> I guess if you do a lot of that sort of thing you can try to convert the
>> object to IDisposable and dispose of it if it succeeds.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Find great Windows Forms articles in Windows Forms Tips and Tricks
>> http://www.bobpowell.net/tipstricks.htm
>>
>> Answer those GDI+ questions with the GDI+ FAQ
>> http://www.bobpowell.net/faqmain.htm
>>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>>
>>
>>
>>
>> "Dennis" <(E-Mail Removed)> wrote in message
>> news:FF6483BE-7577-4991-98EE-(E-Mail Removed)...
>> >I thought so. I see lots of examples in MSDN that use the first code so
>> >I
>> > guess they don't dispose of the objects and leave it to the GC.
>> >
>> > "Scott M." wrote:
>> >
>> >> Your second bit of code is your solution.
>> >>
>> >> "Dennis" <(E-Mail Removed)> wrote in message
>> >> news:1F1E1B11-425A-4C5F-9C3F-(E-Mail Removed)...
>> >> > Ok, I'm trying to dispose of every object that I create that has a
>> >> > dispose
>> >> > method based on advice from this newsgroup. However, I'm not sure
>> >> > how
>> >> > to
>> >> > dispose of the following object that was created inside a method
>> >> > call.
>> >> >
>> >> > dim myvar as new object1
>> >> > object1.dosomethingmethod(new object2)
>> >> >
>> >> > Note that object 2 has a dispose method but how do I dispose of it
>> >> > unless
>> >> > I
>> >> > do the following:
>> >> >
>> >> > dim myvar as new object1
>> >> > dim mydisposableobject as new object 2
>> >> > object1.dosomethingmethod(mydisposableobject )
>> >> > myotherobject.Dispose
>> >> >
>> >> >
>> >> > --
>> >> > Dennis in Houston
>> >>
>> >>
>> >>
>>
>>
>>