I have a global variable that is of type Image. I set this to different
images in different routins using BitBlt to copy from the screen. If I
dispose of the variable image after I'm thru with each image, not only the
image is disposed but also the variable and I can't reference it again.
Question is do I need to dispose of the old image each time I change the
variable's image or will the old image be disposed by the garbage collector?
I have the same problem with a font variable. Thanks for any answer.
dim myimage as bitmap
private sub dosomething()
myimage = get_imageno1
myimage.dispose
......
end sub
Private sub dosomethingelse()
myimage = get_imageno2
.........
end sub
--
Dennis in Houston 6 1211
Dennis,
Why you make your Image global when you want to dispose it all the time, is
this not more efficient in the way you are using it.
\\\
dim myimage as bitmap
private sub dosomething()
dim myimage as bitmap
myimage = get_imageno1
myimage.dispose
......
end sub
///
Cor
Doh
\\\
private sub dosomething()
dim myimage as bitmap
myimage = get_imageno1
myimage.dispose
.......
end sub
/// Cor
"Dennis" <De****@discussions.microsoft.com> schrieb: I have a global variable that is of type Image. I set this to different images in different routins using BitBlt to copy from the screen. If I dispose of the variable image after I'm thru with each image, not only the image is disposed but also the variable and I can't reference it again.
You can use the variable, but you cannot/should not access its properties if
the object the variable is pointing to is disposed. In order to be able to
access instance members, you'll need to instantiate a new object and assign
it to the variable:
\\\
myimage = New Bitmap(...)
....
///
Question is do I need to dispose of the old image each time I change the variable's image or will the old image be disposed by the garbage collector?
It will be disposed if the GC calls the object's finalizer before actually
destroying the object. Nevertheless it's better to call 'Dispose'
explicitly in order to keep memory usage and usage of unmanaged resources
(GDI handles, for example), small. It's the same for 'Font' objects, pens,
brushes, and 'Graphics' objects (and some other objects).
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks.
"Herfried K. Wagner [MVP]" wrote: "Dennis" <De****@discussions.microsoft.com> schrieb:I have a global variable that is of type Image. I set this to different images in different routins using BitBlt to copy from the screen. If I dispose of the variable image after I'm thru with each image, not only the image is disposed but also the variable and I can't reference it again.
You can use the variable, but you cannot/should not access its properties if the object the variable is pointing to is disposed. In order to be able to access instance members, you'll need to instantiate a new object and assign it to the variable:
\\\ myimage = New Bitmap(...) .... ///
Question is do I need to dispose of the old image each time I change the variable's image or will the old image be disposed by the garbage collector?
It will be disposed if the GC calls the object's finalizer before actually destroying the object. Nevertheless it's better to call 'Dispose' explicitly in order to keep memory usage and usage of unmanaged resources (GDI handles, for example), small. It's the same for 'Font' objects, pens, brushes, and 'Graphics' objects (and some other objects).
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I need it to be global because I use it in different mouse events. For
example, in the mousedown event, I copy a rectangular area of my panel (only
part of the panel) using bitblt to a global bitmap object. In the mousemove
event, I draw something else in the area of the rectangle. In the MouseUP
event, I replace the original rectangular area with the original bitmap to
restore the area to what it was before I drew on it in the mouse move event.
How do I do this without using a global variable assigned to the original
rectangle?
"Cor Ligthert" wrote: Dennis,
Why you make your Image global when you want to dispose it all the time, is this not more efficient in the way you are using it.
\\\ dim myimage as bitmap private sub dosomething() dim myimage as bitmap myimage = get_imageno1 myimage.dispose ...... end sub ///
Cor
Dennis,
When you need to use it global than you can not dispose it in my opinion.
What you want to use when it is not anymore there?
Cor
"Dennis" <De****@discussions.microsoft.com> I need it to be global because I use it in different mouse events. For example, in the mousedown event, I copy a rectangular area of my panel (only part of the panel) using bitblt to a global bitmap object. In the mousemove event, I draw something else in the area of the rectangle. In the MouseUP event, I replace the original rectangular area with the original bitmap to restore the area to what it was before I drew on it in the mouse move event. How do I do this without using a global variable assigned to the original rectangle?
"Cor Ligthert" wrote:
Dennis,
Why you make your Image global when you want to dispose it all the time, is this not more efficient in the way you are using it.
\\\ dim myimage as bitmap private sub dosomething() dim myimage as bitmap myimage = get_imageno1 myimage.dispose ...... end sub ///
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Egghead |
last post by:
Hi all,
I'm just wondering that is any way to dispose all objects when my app is
shut down? I mean I can use for.. next loop to unload all loaded form when I
shut down my app.
Thank you,
...
|
by: Chris Capel |
last post by:
I've heard a lot of talk on the forum about memory managment in .NET and
disposing things, finalizing them, garbage collection, etc. My question is
which managed types need to be disposed after...
|
by: MC D |
last post by:
Question:
If I have a class which has a property which is a collection of widget
objects (an arrayList of widgets), and both the containter class and the
widget class implement the IDisposable...
|
by: Mathias L. |
last post by:
I have two questions for which I couldnt find answer:
If I programaticaly close DialogForm (calling Close()), is it enough or do I
have to dispose it as MS.NET help says?
Also, in overriden...
|
by: sunitabalakrishna |
last post by:
Hi,
Could someone explain me if I need to implement the Dispose pattern on
managed objects that hold objects which have longer life or is a
singleton?
Example -
Class A holds Class Global...
| |
by: Mariusz |
last post by:
Hello,
I have question regarding disposing objects in aspx/cs pages. If I create
some objects/Arrays/ListArrays in pageLoad do I have to dispose them (by
assigning the null value for objects that...
|
by: Gman |
last post by:
Hi,
Objective:
Draw a grid on a bitmap and set this as a panel's image. (Rather than
draw the grid directly on the panel and redraw repeatedly in the paint
event.)
Problem:
It works fine....
|
by: Adam Right |
last post by:
Hi,
I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and the
other forms are opened in this form. For...
|
by: Rob |
last post by:
Hi all,
I wrote myself a little function to do my own housekeeping, I can call
it by using
Dispose(object)
Within this function there's a select case statement which will then,
based on...
|
by: Jerry Spence1 |
last post by:
I'm rather confused as to whether something should be disposed of, or not.
What is the general rule? How can you be sure of doing the right thing? I've
heard about disposing unmanaged resources but...
|
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,...
| |
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...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |