Java access in Rhino JavaScript engine can be used to get soft, weak references in scripts. For example, we may define the following script wrappers:
Object.prototype.softRef = function() {
return new java.lang.ref.SoftReference(this);
}
Object.prototype.weakRef = function() {
return new java.lang.ref.WeakReference(this);
}
Because we have added function properties to Object.prototype, we can create soft, weak references of any script object as shown below:
var x = "hello";
// create a SoftReference of script String 'hello'
x = x.softRef();
// may get null or "hello" depending on whether
// the SoftReference is cleared or not
x.get();
Posted by Attila Szegedi on October 29, 2005 at 01:15 AM IST #
Posted by A. Sundararajan on October 29, 2005 at 06:25 PM IST #