I've always been confused/unsure about how .Net copies references. Let's say I have a Bitmap object for GDI+.
dim foo as new bitmap("c:\foo.bmp")
'Foo' holds the bitmap object. Now let's say I do this.
dim bar as bitmap = foo
Is this a shallow copy or a deep copy? If I set foo equal to nothing, does bar suddenly reference 'nothing' as well? Or does bar contain a copy of the bitmap as well, and in order to remove the bitmap from memory completely, I need to set both 'foo' and 'bar' to nothing?
I need to keep a library of bitmaps in memory, and to me it would be easier to just store a reference to each bitmap in each created object as a variable, instead of coding it with an index and having to refer to the library each time it is needed (such as 'BitmapLibrary.Singleton.getBitmap(id)')
In a nutshell, can I do this:
struct graphic object
dim myBitmap as bitmap
sub draw(g as graphics)
g.drawimage(myBitmap)
end sub
instead of this:
struct graphic object
dim myBitmapIndex as integer
sub draw(g as graphics)
g.drawimage(bitmaplibrary.getImage(myBitmapIndex))
end sub