473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

"Disposing" of graphics objects?


Hi there,
Do I need to call "Dispose" on System.Drawing.Brush and System.Drawing.Pen
if I've created new ones? What if I'm using stock brushes and pens? Also,
do I need to explicitly call "Dispose" on Graphics too? In all cases in my
code, they are local variables anyway. Won't VB.NET dispose them
automatically when the function exits?

Thanks for any tips,


Robin
Nov 21 '05 #1
2 2411
Robin,

When IDisposable is implemented in a class, VBNet should dispose everything
(including all so called unmanaged resources), however you do not know when,
so is told that by the larger objects calling dispose does not harm that
much, just to force it to let it go a little bit faster.

Cor

"Robin Tucker
Hi there,
Do I need to call "Dispose" on System.Drawing.Brush and System.Drawing.Pen
if I've created new ones? What if I'm using stock brushes and pens? Also, do I need to explicitly call "Dispose" on Graphics too? In all cases in my code, they are local variables anyway. Won't VB.NET dispose them
automatically when the function exits?

Nov 21 '05 #2
* "Robin Tucker" <id*************************@reallyidont.com> scripsit:
Do I need to call "Dispose" on System.Drawing.Brush and System.Drawing.Pen
if I've created new ones?
Yes.
What if I'm using stock brushes and pens?
You should not dispose these objects.
Also, do I need to explicitly call "Dispose" on Graphics too?
Yes, if you use 'CreateGraphics' or similar to /create/ such an object.
In side event handlers often a 'Graphics' object is supplied in
'e.Graphics'. You don't need to/should not dispose these objects.
code, they are local variables anyway. Won't VB.NET dispose them
automatically when the function exits?


The object will be disposed sooner or later, but there is no guarantee
when it will be disposed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
10
by: Andreas Müller | last post by:
Hi all, I have a class SwitchCursor, that implements IDisposable. Is it legal to use an object that is not assigned to a reference inside a using statement like this: using(new...
2
by: Serge Klokov | last post by:
Hi! 1. Please, help with example "paint on form by mouse" 2. Below is my example, but it clear the line after each Refresh()... how to fix? 3. How to draw the line in Mouse_Move event? ...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
10
by: Paul | last post by:
Hi, I was wondering if anyone knows if it is possible in C# given x,y coordinates of several straight lines to draw these on the screen and then save this as an image file, also adding text to the...
4
by: =?Utf-8?B?R2Vy?= | last post by:
Hi, I use vb2003 on sbs2003 with SQL2000. I have a form with IEWebControls. Under the MultiPage I have some aspx-files, which are selected in an iFrame. In the codebehind I want to dispose not...
12
by: Dom | last post by:
VB had a "line" control, just a simple line that let you separate controls without the wasted space of a Groupbox. Did CSharp drop this? Dom
11
by: Jon Mcleod | last post by:
I'm trying to wrap my ming around C#/CLR garbage collection. In an ASP.NET project, I'm having a problem because an object destructor is being called by another thread, long after my code is done....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.