edvin / tornadofx

Lightweight JavaFX Framework for Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fragment instance leaks when using replaceWith()

mswokk opened this issue · comments

I had a memory leaking problem when replacing Fragments.
And I found the cause and fixed it.

Cause:
Leaking point is in Component.kt > rootSceneChangeListener
When adding a windowProperty() change listener, it uses onChangeOnce() utility method.
onChangeOnce() is designed to unregister the listener itself when it called once.
But replacing the scene with Fragment or VIew, the windowProperty is not changed and not called
Hence, the window instance holds the windowProperty() change listener and never releases.

Minimal reproduction:
Repeat several times to calling ...
replaceWith() from AView ,
replaceWith() from AFragment

And check the JVM heap histogram with jmap command.
jmap -histo:live (PID) | grep AFragment

The number of instance of AFragment should be one, but it wasn't.

I created a PR for this issue.