简体   繁体   English

JavaFx Webview内存泄漏事件

[英]JavaFx Webview memory leak on events

We're currently developing an application which hugely relies on the JavaFx webview. 我们目前正在开发一个非常依赖JavaFx Web视图的应用程序。 The layout is loaded by the FXMLLoader and contains a webview with several events like OnScroll, OnMousePressed and OnMouseReleased. 布局由FXMLLoader加载,并包含一个Web视图,其中包含多个事件,如OnScroll,OnMousePressed和OnMouseReleased。

After closing the stage which contains this layout, the stage is properly released from memory, but the controller class stays. 关闭包含此布局的舞台之后,舞台将从内存中正确释放,但控制器类保留。 I investigated this issue with the help of VisualVM. 我在VisualVM的帮助下调查了此问题。

Each time I open and close a stage, a new controller class gets loaded into memory and remains there. 每次我打开和关闭一个阶段时,都会将一个新的控制器类加载到内存中并保留在那里。

In the screenshot below you can see the nearest GC root to my controller class. 在下面的屏幕截图中,您可以看到离我的控制器类最近的GC根。 Highlighted is the OnScroll event of my webview. 突出显示的是我的Webview的OnScroll事件。 If i were to remove this event, the next event (OnMouseReleased) would take it's place in this trace. 如果我要删除此事件,则下一个事件(OnMouseReleased)将取代此事件。 Webview事件泄漏

We're using java version jdk1.8.0_65 and JavaFx version 8.0.65-b17. 我们正在使用Java版本jdk1.8.0_65和JavaFx版本8.0.65-b17。

I'm not sure if I'm doing something wrong, or if its a bug in JavaFx. 我不确定我是在做错什么,还是JavaFx中的错误。 However, this is a show stopper for us and any help is greatly appreciated. 但是,对于我们来说,这是一个表演停止器,我们将不胜感激。

Best of wishes, Mazen 最好的祝愿,Mazen

I found it. 我找到了。

The problem weren't webview events. 问题不是webview事件。 The problem wasn't even the webview itself. 问题甚至不是webview本身。 Upon further investigation I found out that the whole scene with every component on it was still in memory. 经过进一步调查,我发现整个场景以及其中的每个组件仍在内存中。

The problem is the ProgressIndicator I have in my layout. 问题是我的布局中有ProgressIndicator。 If it is set to an indeterminate state it prevents the scene from getting garbage collected. 如果将其设置为不确定状态,则会阻止场景收集垃圾。 Resetting the progress to 0 (and therefore making it determinate) prior to closing the stage solved my problem. 在关闭舞台之前将进度重置为0(因此确定),可以解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM