Last updated at 9:19 am UTC on 6 March 2020
The Inspector one of the three important tools in Smalltalk to study object instances. It is used to inspect the class contents (instance variables) of a live object, its class or to send messages to it.
The other two tools are the Browser (study classes and their methods) and Object Explorer (used to explore references from an object to other objects in an hierarchical tree). Explorer is more advanced than the Inspector. Squeak versions 5+ have a button to switch between inspecting and exploring an object in the same window.
To open an inspector, highlight an object or snippet of Smalltalk code in a Workspace or other text window, and select "inspect it" from the pop-up menu. (or use alt-i)
For example, open a Workspace and type 3@4 into it, then highlight this text and "inspect it".
This will open an inspector window on the object, with the object's instance variables in a column on the top-left, a variable display area on the top-right, and a code area on the bottom. In this code area, you can send messages to the object, by entering something like self printString or self printString asSortedCollection and then alt-p or alt-i.
An object with an open Inspector will not be garbage collected.
Apart from observing the class and instance variables, you can also trace the references from the roots to an object by using "chase pointers". (Note that the "chase pointers" feature [of the Inspector] can be misleading as it is assumed that for this feature you are interested in "all but" the reference paths starting from the inspector you hold).
The Inspector also allows you to explore pointers. The PointerExplorer shows each object's identityHash as its "name", to allow the user to identify when two similar objects are identical and notice cycles. The tool works like Object Explorer but backwards. When it shows a tree of objects, expanding a node shows you the objects that refer to this node instead of the other way around. Its main use is to track down why a particular object is still hanging around and not being garbage collected. Open an inspector on the object and drill down its incoming references until you find the root object that's referencing it.
in the code pane of the Inspector object you get a Browser showing the code of the class of the object.
In recent version of Squeak you may drag out a field from the list in the inspector and drop it into a Workspace to get a reference to it there.
- Smalltalk is the dictionary which holds all global variables (including many classes).
- Project current is your current workspace.
- Objects instances in Squeak form a directed graph. There are two starting points (roots) to all the objects in the system:
which basically holds everything the VM needs to know to resume an image, and in turn almost every object in the whole image, and
which holds the current execution context including temporary objects (this is what you see in a debugger on the bottom right panel). When a garbage collection is performed, any object not reachable form either of these two roots is removed from memory.