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

Disposing of Objects -AGAIN

P: n/a
I don't think I clearly stated my problem in my prior question so let me try
again. I have the following:

Private myobject as Bitmap

myobject = mybitmap (created from a part of the screen)

How do I dispose of the instance of mybitmap object yet retain myobject so I
can use it again like:

myobject = mysecondbitmap

If I do a myobject.Dispose, I can no longer assign the variable myobject to
another bitmap. If I set myobject to nothing, the instantance of mybitmap
and mysecondbitmap are still existing and have to wait for the GC to dispose
of them.

--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi,

Take a look at Bitmap.clone.

http://msdn.microsoft.com/library/de...clonetopic.asp

Ken
-----------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
I don't think I clearly stated my problem in my prior question so let me try
again. I have the following:

Private myobject as Bitmap

myobject = mybitmap (created from a part of the screen)

How do I dispose of the instance of mybitmap object yet retain myobject so I
can use it again like:

myobject = mysecondbitmap

If I do a myobject.Dispose, I can no longer assign the variable myobject to
another bitmap. If I set myobject to nothing, the instantance of mybitmap
and mysecondbitmap are still existing and have to wait for the GC to dispose
of them.

--
Dennis in Houston
Nov 21 '05 #2

P: n/a
"Dennis" <De****@discussions.microsoft.com> schrieb:
I don't think I clearly stated my problem in my prior question so let me
try
again. I have the following:

Private myobject as Bitmap

myobject = mybitmap (created from a part of the screen)

How do I dispose of the instance of mybitmap object yet retain myobject so
I
can use it again like:

myobject = mysecondbitmap


Mhm... I don't understand why you want to dispose the instance if you still
need it...

--
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

P: n/a
I want to dispose of the first bitmap I created after I've finished using it
and set the variable myObject to reference a different bitmap so on the next
call to my functions, it will use the different bitmap. I can't pass the
variable as a parameter because I am working with MouseEvents.

"Dennis" wrote:
I don't think I clearly stated my problem in my prior question so let me try
again. I have the following:

Private myobject as Bitmap

myobject = mybitmap (created from a part of the screen)

How do I dispose of the instance of mybitmap object yet retain myobject so I
can use it again like:

myobject = mysecondbitmap

If I do a myobject.Dispose, I can no longer assign the variable myobject to
another bitmap. If I set myobject to nothing, the instantance of mybitmap
and mysecondbitmap are still existing and have to wait for the GC to dispose
of them.

--
Dennis in Houston

Nov 21 '05 #4

P: n/a

"Dennis" <De****@discussions.microsoft.com> wrote
I want to dispose of the first bitmap I created after I've finished using it
and set the variable myObject to reference a different bitmap so on the next
call to my functions, it will use the different bitmap. I can't pass the
variable as a parameter because I am working with MouseEvents.


Perhaps you could supply a more complete example, something small that
can be pasted into a new form, to see what it is you say isn't working.

This statement of yours is in error....
If I do a myobject.Dispose, I can no longer assign the variable myobject to
another bitmap.


You don't assign variables to bitmaps, you assign bitmaps to variables. Using
dispose on the bitmap, after you are done with it, is the proper course of action.

LFS
Nov 21 '05 #5

P: n/a
Larry,

This is done in a long thread before unluckily Dennis started a new thread
and than you get this kind of starting every discussion new again.

The problem is that Dennis has its bitmap globaly and want to keep the
bitmap, what he wants is and I don't know it that works.

\\\
dim mybitmap as bitmap
public sub whatever
if Not mybitmap Is Nothing then
mybitmap.dispose
end if
mybitmap = New bitmap(.....)
end sub
///

Cor
Nov 21 '05 #6

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote
This is done in a long thread before unluckily Dennis started a new thread
and than you get this kind of starting every discussion new again.


Thank you Cor, as busy as I have been, I'll probably have to lurk a while
to watch for new threads, instead of jumping in the middle of finished
discussions....

:-)
LFS
Nov 21 '05 #7

P: n/a
Thanks Cor for clarifying my problem. That's excatly what I wnat to do.
However, when executing the code, I get an error on the line mybitmap = new
bitmap(...) saying "Invalid Parameter Used" because, I think, when I use the
mybitmap.dispose, it disposes not only the bitmap but destroys the variable
mybitmap.
"Cor Ligthert" wrote:
Larry,

This is done in a long thread before unluckily Dennis started a new thread
and than you get this kind of starting every discussion new again.

The problem is that Dennis has its bitmap globaly and want to keep the
bitmap, what he wants is and I don't know it that works.

\\\
dim mybitmap as bitmap
public sub whatever
if Not mybitmap Is Nothing then
mybitmap.dispose
end if
mybitmap = New bitmap(.....)
end sub
///

Cor

Nov 21 '05 #8

P: n/a
Dennis,

This I could do endless
\\\
Private mybitmap As Bitmap
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
If Not mybitmap Is Nothing Then
mybitmap.Dispose()
End If
mybitmap = New Bitmap("c:\test1\mybitmap.bmp")
End Sub
///

So what is in your parameter.
http://msdn.microsoft.com/library/de...sctortopic.asp

We only saw that it was probably a function returning something
Cor

"Dennis" <De****@discussions.microsoft.com>
Thanks Cor for clarifying my problem. That's excatly what I wnat to do.
However, when executing the code, I get an error on the line mybitmap =
new
bitmap(...) saying "Invalid Parameter Used" because, I think, when I use
the
mybitmap.dispose, it disposes not only the bitmap but destroys the
variable
mybitmap.
"Cor Ligthert" wrote:
Larry,

This is done in a long thread before unluckily Dennis started a new
thread
and than you get this kind of starting every discussion new again.

The problem is that Dennis has its bitmap globaly and want to keep the
bitmap, what he wants is and I don't know it that works.

\\\
dim mybitmap as bitmap
public sub whatever
if Not mybitmap Is Nothing then
mybitmap.dispose
end if
mybitmap = New bitmap(.....)
end sub
///

Cor

Nov 21 '05 #9

P: n/a
"Dennis" <De****@discussions.microsoft.com> schrieb:
However, when executing the code, I get an error on the line mybitmap =
new
bitmap(...) saying "Invalid Parameter Used" because, I think, when I use
the
mybitmap.dispose, it disposes not only the bitmap but destroys the
variable
mybitmap.


Please post the complete code calling the 'Bitmap' constructor.

--
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 #10

P: n/a
Thanks Cor, you've helped solve my problem. What was happening was that I
had code similiar to yours but had a test for mybitmap is nothing before
resetting it to a different bit map. Thanks..this has been driving me nuts
for sometime now.

Private mybitmap As Bitmap
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
If Not mybitmap Is Nothing Then
mybitmap.Dispose()
End If
If mybitmap Is Nothing then mybitmap = New Bitmap("c:\test1 _
\mybitmap.bmp")

......... Use mybitMap for something (got errorhere)
End Sub

What apparently happens is that when you do a mybitmap.dispose, it doesn't
set the variable mybitmap to Nothing so next time I try to set mybitmap to a
new bitmap based on it being nothing, it doesn't get set because mybitmap is
not nothing...not sure what it is but it's sure not nothing.

"Cor Ligthert" wrote:
Dennis,

This I could do endless
\\\
Private mybitmap As Bitmap
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
If Not mybitmap Is Nothing Then
mybitmap.Dispose()
End If
mybitmap = New Bitmap("c:\test1\mybitmap.bmp")
End Sub
///

So what is in your parameter.
http://msdn.microsoft.com/library/de...sctortopic.asp

We only saw that it was probably a function returning something
Cor

"Dennis" <De****@discussions.microsoft.com>
Thanks Cor for clarifying my problem. That's excatly what I wnat to do.
However, when executing the code, I get an error on the line mybitmap =
new
bitmap(...) saying "Invalid Parameter Used" because, I think, when I use
the
mybitmap.dispose, it disposes not only the bitmap but destroys the
variable
mybitmap.
"Cor Ligthert" wrote:
Larry,

This is done in a long thread before unluckily Dennis started a new
thread
and than you get this kind of starting every discussion new again.

The problem is that Dennis has its bitmap globaly and want to keep the
bitmap, what he wants is and I don't know it that works.

\\\
dim mybitmap as bitmap
public sub whatever
if Not mybitmap Is Nothing then
mybitmap.dispose
end if
mybitmap = New bitmap(.....)
end sub
///

Cor


Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.