使用JavaFX-3D创建动画时内存泄漏

时间:2016-08-31 16:01:09

标签: memory-leaks javafx-8 javafx-3d java-memory-leaks

我构建了一个JavaFX(8)3D应用程序,它从某个文件中读取数据并在某个场景中呈现它。

为了渲染对象,我使用:

created = article.created_at
updated = article.updated_at

minutes = (updated - created) / 1.minutes

当我注释掉这一行时,为了禁用渲染,我根本没有内存泄漏。

但是当这一行运行时,应用程序会消耗越来越多的内存。我每秒有30帧,每秒内存消耗大约增加50MB。

当然,这是在我使用的帧之间:

graphicsContainer.getChildren().add(some3dObject);

我分配给graphicsContainer.getChildren().clear(); 的3D对象是本地的,不会保存在任何静态/全局范围内。它们仅保存为graphicsContainer的子项,每帧都清理一次。

虽然每次graphicsContainer的孩子都删除了,但JavaFX-3D引擎中的某些东西似乎并没有真正清除我的工作。

知道如何让JavaFX 3D引擎发布过去的3D对象和渲染吗?

1 个答案:

答案 0 :(得分:0)

In my scenario, all the frames contain the same set of 3D objects. The only thing that changes from frame to frame is the locations and the transformations of these objects.

My workaround was to save in some array each 3D object I create (Sphere, Cylinder, etc.) - then on each frame, I just change their location and transformations, instead of creating new Group and new 3D objects each time.

The memory is now around 220MB all the time.