The java::lock Command


Usage:

java::lock javaObj

The java::lock command prevents the Java object, javaObj, from getting garbage collected. A Tcl variable that stores a Java object handle has an internal rep that holds a reference to the Java object. If the Tcl variable's internal rep is changed (e.g. to a Tcl List), the reference to the Java object is removed, and the Java object could be garbage collected. The java::lock command maintains a copy of javaObj's internal rep, so the Java object will be not be garbage collected. Multiple locks can be placed on the same Java object. If javaObject is not a valid reference to a Java object, a Tcl error is generated. It is important to note that use of the java::lock command is optional, it is not required. A Java object handle that is stored in a Tcl variable will not be garbage collected unless the Tcl variable is unset, or the internal representation is changed.

Copyright © 1997-1998 Sun Microsystems, Inc.