Hexworks / zircon

Zircon is an extensible and user-friendly, multiplatform tile engine.
https://hexworks.org/projects/zircon/
Apache License 2.0
752 stars 137 forks source link

BaseGameArea sticks in memory after undocking #376

Closed Loomie closed 3 years ago

Loomie commented 3 years ago

Describe the bug After looking in a heap dump of our Zircon application I found a no longer shown GameArea (and its references). The problem is that Cobalt is not used properly 😛 In BaseGameArea.init an onChange listener is registered. But it is never unregistered! So the EventBus of Cobalt holds that listener forever. That listener has a reference to the GameArea and therefore to our own code.

To Reproduce

screen.dock(viewWithGameArea)
screen.dock(otherView)

Do a garbage collection (GC) and create a heap dump.

Expected behavior No instance of the no longer used View should linger in the memory.

Screenshots gcroot

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

Loomie commented 3 years ago

Created PR #377 with a proposed fix.

nanodeath commented 3 years ago

init block in question: https://github.com/Hexworks/zircon/blob/master/zircon.core/src/commonMain/kotlin/org/hexworks/zircon/api/game/base/BaseGameArea.kt#L49-L51