Only programmers that create new object types need to be concerned about how this is done. A procedure defined as part of the object type's implementation creates a new internal representation for an object and changes its typePtr . This procedure checks whether the object is already an integer object. Both representations are now valid. The string representation is now 124 .
Reference counting is used to determine when an object is no longer needed and can safely be freed.
An object shared by different code or data structures has refCount greater than 1. As an example, the bytecode interpreter shares argument objects between calling and called Tcl procedures to avoid having to copy objects. It assigns the call's argument objects to the procedure's formal parameter variables. Most command pro- cedures do not have to be concerned about reference counting since they use an object's value immediately and don't retain a pointer to the object after they return. However, if they do retain a pointer to an object in a data structure, they must be careful to increment its reference count since the retained pointer is a new reference.