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. Incrementing an object's reference count ensures that it won't be freed too early or have its value change accidently. 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 procedures 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.