Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.85k stars 819 forks source link

Starling 1.8 > Canvas > Memory leak due to wrong event listener registration #858

Closed eyal-katz closed 8 years ago

eyal-katz commented 8 years ago

Hey

Checkout Canvas.as, line ~65 (Starling v1.8) You will see: Starling.current.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);

Where it should listen to stage 3d with weak references (like other starling display classes): Starling.current.stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated, false, 0, true);

This bug currently causes every Canvas ever created to be kept in memory....

Eyal

PrimaryFeather commented 8 years ago

Well, it's not a problem for every Canvas object, only for those that are not disposed by the developer - which he/she should always do, anyway. :wink: But you're right, of course: the reason I'm using the other kind of listener in the other classes also applies here. I'll make that change!

Thanks a lot for the heads-up!

eyal-katz commented 8 years ago

Canvas.dispose() does not remove the listener, so I think it happens for every Canvas... am I wrong?

(Daniel, I will write a song about you one day, it will be an ode with a lot of brave words in it...)

PrimaryFeather commented 8 years ago

Eyal, you're completely right! With that other line missing, this does cause memory leaks. I should have checked that right away!

In any case, a fix will be coming right away - no need for a song just yet! :wink: