Submit a request
Submit a request

Cleaning up an Author API Instance Using .destroy()

As a developer, you have the ability to destroy an Author API instance.

It's a very useful action to perform, especially when you're building a single page app. This way you can navigate away from the Author API view, destroying it right afterwards, and freeing all the memory. This will prevent possible memory leaks.

Calling the destroy method should only be done after the Author API has finished its initialization. This can be done by utilizing the readyListener callback method. Please look at the example code below to see how it could be achieved:

 

// assuming here that signed `initOptions` object exists
var authorApp = LearnosityAuthor.init(initOptions, {
    readyListener: function () {
        // from now on it's safe to destroy()
        authorApp.destroy();
    }
});

 

Currently, this only works when the question_editor_api.preload dependency option is set to false. If it's set to true and if Question Editor has not been initialized (or hasn't finished) yet, then calling destroy method will throw an error.

Was this article helpful?
0 out of 0 found this helpful

Did you arrive here by accident? If so, learn more about Learnosity by clicking here.