From 68a6f2f8aaeaf680e5731514dd231c4b4183a382 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 4 Dec 2012 09:23:32 +0100 Subject: [PATCH] js: Doc how to clean up after Mopidy.js --- mopidy/frontends/http/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mopidy/frontends/http/__init__.py b/mopidy/frontends/http/__init__.py index 7697b60e..d81d4791 100644 --- a/mopidy/frontends/http/__init__.py +++ b/mopidy/frontends/http/__init__.py @@ -305,6 +305,28 @@ refer to when.js' documentation or the standard for further details on how to work with promise objects. +Cleaning up +----------- + +If you for some reason want to clean up after Mopidy.js before the web page is +closed or navigated away from, you can close the WebSocket, unregister all +event listeners, and delete the object like this: + +.. code-block:: js + + // Close the WebSocket without reconnecting. Letting the object be garbage + // collected will have the same effect, so this isn't striclty necessary. + mopidy.close(); + + // Unregister all event listeners. If you don't do this, you may have + // lingering references to the object causing the garbage collector to not + // clean up after it. + mopidy.off(); + + // Delete your reference to the object, so it can be garbage collected. + mopidy = null; + + Example to get started with ---------------------------