Revision: 2969 http://vexi.svn.sourceforge.net/vexi/?rev=2969&view=rev Author: mkpg2 Date: 2008-07-18 10:37:30 +0000 (Fri, 18 Jul 2008)
Log Message: ----------- Make picture objects behave better with references w.r.t. garbage collection. Modified Paths: -------------- trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java Modified: trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java 2008-07-18 09:55:00 UTC (rev 2968) +++ trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java 2008-07-18 10:37:30 UTC (rev 2969) @@ -8,10 +8,7 @@ import java.io.PushbackInputStream; import java.util.WeakHashMap; -import org.ibex.js.Fountain; -import org.ibex.js.JS; -import org.ibex.js.JSExn; -import org.ibex.js.Scheduler; +import org.ibex.js.*; import org.ibex.util.Callable; import org.ibex.util.Log; import org.ibex.util.Vec; @@ -54,9 +51,21 @@ } /** turns a stream into a Picture.Source and passes it to the callback */ - public static Picture load(JS stream, Callable callback) { - Picture ret = (Picture)cache.get(stream); - if (ret == null) cache.put(stream, ret = Platform.createPicture(stream)); + public static Picture load(JS stream_, Callable callback) throws JSExn { + // REMARK - remove blessing. We do this because the blessing + // holds references which can prevent proper garbage collection. + //Fountain streamx = JSU.getFountain(stream_); + // REMARK - + // + final Blessing b = Blessing.getBlessing(stream_); + Fountain stream = b == null ? + JSU.getFountain(stream_) : b.getImage(); + String key = stream.canonical(); + //String key = JSU.getFountain(stream_).canonical(); + //JS stream = stream_; + + Picture ret = (Picture)cache.get(key); + if (ret == null) cache.put(key, ret = Platform.createPicture(stream)); // can return ret here outside of sync block for caller to assign as callback // is executed in the same interpreter as the caller, synchronously. ret.load(callback); @@ -75,14 +84,12 @@ return; } - final Blessing b = Blessing.getBlessing(stream); loadedCallbacks = new Vec(); loadedCallbacks.addElement(callback); new java.lang.Thread() { public void run() { try { - InputStream in = b == null ? - Fountain.getInputStream(stream) : b.getImage(); + InputStream in = Fountain.getInputStream(stream); if (in == null) throw new JSExn("not a valid image stream"); PushbackInputStream pbis = new PushbackInputStream(in); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn