1.6.17 Tracing Shared Objects in Memory

The Debugger Shows Objects Through Variables

Visual Studio displays a variable and the fields of the object it reaches. Two expanded variables may show the same fields because they lead to one object.

Two debugger entries display the same Player with the name Casey.
Initial relationship
  • New
  • Changed
  • Removed
An Alias Has the Same Displayed State

After these statements execute:

Player alias = original;
alias.Name = "Casey";

Locals displays Name Casey under both `alias` and `original`. The repeated field display provides two views of one Player; it does not show a copied Player.

A new Expression Changes the Picture

After `alias = new Player();`, there are two Players. The old Player is still reached by `original`. The new Player is reached by `alias`.

Different Values Reveal Different Objects

If `alias.Name` then becomes Morgan, Locals shows `original.Name` as Casey and `alias.Name` as Morgan. Those values belong to two different Players.

The debugger entries now lead to separate Players named Casey and Morgan.
How the relationship changes
  • New
  • Changed
  • Removed
The Display Is a View of Program State

The debugger organizes information for reading; it is not a physical map of memory. The `new` expressions and reference assignments explain how many objects exist and why the displayed fields agree or differ.