Protecting objects from garbage collection
Whenever an object is allocated, a garbage collection might be required. If this happens, all non-immediate object pointers stored in user primitive variables may be invalidated since the garbage collector may move the objects. In addition, if there are no other references to the object, it will be discarded during garbage collection. This means that all new objects that are allocated in a user primitive must be explicitly protected from garbage collection by creating a reference using the EsSaveObject / EsRestoreObject protocol.
Each object that is referenced only by a user primitive variable must be saved before any operation that could cause a garbage collection. After that operation completes, the objects must be restored in the reverse order from that in which they were saved and reassigned to the user primitive variables. All saved objects must be restored before the user primitive succeeds or fails.
void EsSaveObject(EsObject object)
Pushes object onto the Smalltalk stack so that it is protected from a garbage collection.
 
EsObject EsRestoreObject(void)
Pops the object on the top of the Smalltalk stack and returns it.
void EsRememberObjectStore(EsVMContext vmContext, EsObject targetObject, EsObject storedObject)
Must be called whenever an object is stored into an instance variable of a pointer object.
For example,
EsObject myObject;
EsObject storedObject;
EsObject * instVar;
instVar = (EsObject *) EsInstVarAddr(myObject);
*instVar = storedObject;
EsRememberObjectStore(EsPrimVMContext, myObject, storedObject);

Note:
EsAtPut and EsInstVarAtPut automatically call this function.
 
Last modified date: 01/29/2015