#927 – Visualizing How Objects Are Created on the Managed Heap

Suppose that you create a couple of new objects and refer to them using referenced-typed variables, as follows:

            Dog myDog = new Dog("Kirby", 15);
            Dog yourDog = new Dog("Bowser", 3);

You now have two variables of type Dog, each referring to an instance of a Dog object.  The Dog objects exist on the managed heap.

927-001

Suppose that you now change the yourDog variable to also reference the “Kirby” dog, as follows:

            yourDog = myDog;

The managed heap still contains the two original Dog objects. But notice that the “Bowser” dog is no longer currently referenced by any reference-typed variables.  Bowser is no longer reachable from any of the reference-typed variables, but this Dog object has not yet been destructed, or its memory reclaimed.

972-002

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #927 – Visualizing How Objects Are Created on the Managed Heap

  1. Agent117 says:

    Reblogged this on Phani Kumar Tadepally and commented:
    C# way of heap memory management

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: