当尝试从sbt 0.10.1运行用Scala 2.8.1编写的简单JavaFX 2.0 beta应用程序时,在关闭应用程序窗口后会抛出异常:
> run
[info] Running com.tradex.priceviewer.Main
Exception while removing reference: java.lang.InterruptedException
java.lang.InterruptedException
[ at java.lang.Object.wait(Native Method)success
] at java.lang.ref.ReferenceQueue.remove(Unknown Source)Total time: 5 s, completed Aug 5, 2011 1:12:04 PM
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at com.sun.glass.utils.Disposer.run(Disposer.java:64)>
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
从命令行运行应用程序时,不会抛出异常,返回的状态为0.应用程序的代码如下:
class Starter extends Application {
def main(args: Array[String]) {
Application.launch(args)
}
override def start(s: Stage) {
s.setVisible(true)
}
}
object Main {
def main(args: Array[String]) {
val gui = new Starter
gui.main(args)
}
}
Run Code Online (Sandbox Code Playgroud)
抛出异常后,必须退出并再次启动sbt(重新加载不起作用).从Scala 2.8.1控制台运行相同的应用程序时,在第二次运行后抛出以下异常:
scala> m.main(Array("")) …Run Code Online (Sandbox Code Playgroud) 尝试使用Scala 2.8.1/JavaFx 2.0 beta编译以下代码时
new KeyValue(circle.translateYProperty, random() * height)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
[error] found : javafx.beans.property.DoubleProperty
[error] required: javafx.beans.value.WritableValue[Any]
[error] new KeyValue(circle.translateYProperty, random() * height)
[error] ^
[error] one error found
Run Code Online (Sandbox Code Playgroud)
虽然这行编译得很好:
new KeyValue(circle.translateXProperty.asInstanceOf[WritableValue[Any]], random() * width)
Run Code Online (Sandbox Code Playgroud)
我检查了KeyValue构造函数,它具有以下签名:
public <T> KeyValue(javafx.beans.value.WritableValue<T> tWritableValue, T t) { /* compiled code */ }
Run Code Online (Sandbox Code Playgroud)
circle.translateXProperty返回DoubleProperty,它实现以下接口:
public interface WritableNumberValue extends javafx.beans.value.WritableValue<java.lang.Number>
Run Code Online (Sandbox Code Playgroud)
什么比铸造更优雅的解决方案,使其编译?
JavaFX(1.2.x和1.3.x)似乎不允许至少为节点和场景进行垃圾收集.从Scene中删除后,Node对象不会被释放(没有其他显式引用).
这是一个例子:
var buttonB:Button =
Button {
text: "i'm just hanging here"
}
var buttonC:Button =
Button {
text: "hit me to leak memory"
action: function() {
buttonB.managed = false;
delete buttonB from mainBox.content;
buttonB.skin = null;
buttonB = null;
java.lang.System.gc();
}
}
def mainBox:HBox =
HBox {
hpos: HPos.CENTER
nodeVPos: VPos.CENTER
layoutInfo: LayoutInfo {
width: 800 height: 600
}
content: [buttonC, buttonB]
}
Run Code Online (Sandbox Code Playgroud)
buttonB永远不会被释放.将skin设置为null有助于某种方式(在VisualVM中,大多数对该按钮的引用都会消失),但不能解决问题.我也尝试使用JavaFX反射使所有成员无效而没有运气.
是否可以使buttonB符合GC的要求以及如何操作?
问题是否仍然存在于JavaFX 2.0中?