Tk_Preserve(clientData)
Tk_Release(clientData)
Tk_EventuallyFree(clientData, freeProc)
Tk_Preserve and Tk_Release implement short-term reference counts for their clientData argument. The clientData argument identifies an object and usually consists of the address of a structure. The reference counts guarantee that an object will not be freed until each call to Tk_Preserve for the object has been matched by calls to Tk_Release. There may be any number of unmatched Tk_Preserve calls in effect at once.
Tk_EventuallyFree is invoked to free up its clientData argument. It checks to see if there are unmatched Tk_Preserve calls for the object. If not, then Tk_EventuallyFree calls freeProc immediately. Otherwise Tk_EventuallyFree records the fact that clientData needs eventually to be freed. When all calls to Tk_Preserve have been matched with calls to Tk_Release then freeProc will be called by Tk_Release to do the cleanup.
All the work of freeing the object is carried out by freeProc. FreeProc must have arguments and result that match the type Tk_FreeProc:
This mechanism can be used to solve the problem described above by placing Tk_Preserve and Tk_Release calls around actions that may cause undesired storage re-allocation. The mechanism is intended only for short-term use (i.e. while procedures are pending on the stack); it will not work efficiently as a mechanism for long-term reference counts. The implementation does not depend in any way on the internal structure of the objects being freed; it keeps the reference counts in a separate structure.
Copyright © 1990 The Regents of the University of California. Copyright © 1994 Sun Microsystems, Inc. Copyright © 1995 Roger E. Critchlow Jr.