chunxiao9812 / bst-player

Automatically exported from code.google.com/p/bst-player
0 stars 0 forks source link

Memory Leak in NativePlayerImpl #79

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As per
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener#Me
mory_issues

    public final native void registerMediaStateHandler(NativeEventCallback _callback) /*-{
    this.addEventListener('progress', function(){  // plugin init complete
    _callback.@com.ritmos.web.ui.common.client.media.NativeEventCallback::onProgressChanged()();
    }, false);
    this.addEventListener('play', function(){  // play started
    _callback.@com.ritmos.web.ui.common.client.media.NativeEventCallback::onStateChanged(I)(1);
    }, false);
......

Will likely produce memory issues.

Original issue reported on code.google.com by ciberki...@gmail.com on 30 Apr 2014 at 11:25

GoogleCodeExporter commented 9 years ago
I suggest assigning the listeners to class members so they can be removed when 
detached

Original comment by ciberki...@gmail.com on 30 Apr 2014 at 11:27

GoogleCodeExporter commented 9 years ago
You want something that looks like this:

    public final native void releaseMediaStateHandler()
    /*-{
    this.removeEventListener('loadstart', this.progressListener);
    }-*/;

    public final native void registerMediaStateHandler(NativeEventCallback _callback)
    /*-{
    this.progressListener = function(){  // plugin init complete
    _callback.@com.ritmos.web.ui.common.client.media.NativeEventCallback::onProgressChanged()();
    }; 
    this.addEventListener('loadstart', this.progressListener, false);

And make sure that releaseMediaStateHandler is called onDetach ;)

Original comment by ciberki...@gmail.com on 30 Apr 2014 at 1:22

GoogleCodeExporter commented 9 years ago
Obviestly change com.ritmos.web.ui.common.client.media with
correct package!

Original comment by ciberki...@gmail.com on 30 Apr 2014 at 1:23

GoogleCodeExporter commented 9 years ago

Original comment by sbrah...@gmail.com on 9 May 2014 at 5:14