contents   index   previous   next



seWeakLockObject

 

syntax:

   void

SEContext.seWeakLockObject(SEObject obj,

                           boolean weak);

where:

obj the object to weak lock

 

weak should the object be weak locked

 

return:

None

 

description:

Lock an item to produce a weak lock. The object is always locked, so it must eventually be explicitly freed, just as if you use jseLockObject. The boolean determines if the lock is weak. jseLockObject always produces normal locks. Therefore, this routines is usually used to produce weak locks, so the parameter is true. On occasion, you may need to turn off an existing weak lock and restore it to a full lock which is when the parameter may be false.

 

This API function is designed to resolve a common problem. It is typical when mapping a Java object to a JavaScript object for a programmer to want each item to have a reference to the other. This allows both sides to have access to its sibling to perform any needed task. The problem that arises is that the lock on the ScriptEase object by the API keeps the object permanently in memory, even when ScriptEase is no longer using the object. It is a cyclic loop that cannot be detected because the cycle extends outside of the ScriptEase core.

 

Using seWeakLockObject, the programmer retains a handle to the object but that handle does not lock the object in memory. If ScriptEase is no longer using the object, the presence of this lock does not keep it from being garbage collected. Other than that difference, this function performs exactly like seLockObject.

 

Be careful with this function. The object can be cleaned up at any time once the script is no longer using it. If you try to use a handle to such an object, you will probably crash the system. You should make sure to add a destructor to the object so that you know when you must stop using the handle, and free the handle using seFreeObject at that time. Any use for this function other than this intended one is likely to crash your application.

 

see:

seLockObject, seFreeObject

 


seLockObject