< prev index next >
modules/web/src/main/java/javafx/scene/web/WebEngine.java
Print this page
@@ -248,19 +248,35 @@
public void exit() {
Platform.exit();
}
}
...
+JavaApplication javaApp = new JavaApplication();
JSObject window = (JSObject) webEngine.executeScript("window");
-window.setMember("app", new JavaApplication());
+window.setMember("app", javaApp);
* </code></pre>
* You can then refer to the object and the method from your HTML page:
* <pre><code>
<a href="" onclick="app.exit()">Click here to exit application</a>
* </code></pre>
* <p>When a user clicks the link the application is closed.
* <p>
+ * Note that the property value {@code javaApp} of
+ * JavaScript object named {@code app} is implemented as Weak Global Reference.
+ * <pre><code>
+JSObject window = (JSObject) webEngine.executeScript("window");
+window.setMember("app", new JavaApplication());
+ * </code></pre>
+ * <p>
+ * Hence if the property value is a local object {@code "new JavaApplication()"}, the value will be GC'ed in next
+ * GC Cycle.
+ * <pre><code>
+<a href="" onclick="app.exit()">Click here to exit application</a>
+ * </code></pre>
+ * <p>
+ * When a user clicks the link, it does not guarantee to execute the callback method {@code exit}.
+ * <p>
* If there are multiple Java methods with the given name,
* then the engine selects one matching the number of parameters
* in the call. (Varargs are not handled.) An unspecified one is
* chosen if there are multiple ones with the correct number of parameters.
* <p>
< prev index next >