Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:46:39+00:00 2026-05-15T15:46:39+00:00

I’ve always been confused/unsure about how .Net copies references. Let’s say I have a

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:46:39+00:00Added an answer on May 15, 2026 at 3:46 pm

    In general, references to objects just copy the reference. This is not true for types which inherit from System.ValueType, where it is copied.

    For example:

    Dim foo as new Bitmap("C:\foo.bmp")
    Dim bar as Bitmap = foo
    
    ''//Now close foo
    foo.Dispose()
    ''//Access to bar fails, since the object it was pointing to was the same as foo
    Console.WriteLine(bar.PixelHeight)
    

    For System.ValueType descendants:

    Dim p1 as new Point(1, 2)
    Dim p2 as Point = p1
    
    p1.Offset(1, 0)
    
    Console.WriteLine(p1)  ''//Prints (2, 2)
    Console.WriteLine(p2)  ''//Prints (1, 2)
    

    If I set foo to Nothing, then I’ve just made the reference point to something else (Nothing) and haven’t changed the object which bar references.

    If you are storing a list of objects, storing them in a list structure seems most prudent. However, if you know that you are only going to ever have a fixed, small number of objects, then perhaps keeping the references as fields of a class is a viable option. In your case, you abstract access through the method getImage which is a good design choice, since then users of your class won’t have to bother knowing your strategy for keeping track of references, and you should be able to change it as needed without breaking objects which depend on your class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.