Destroy a promise without a memory leak and not make any callbacks

I use $qto create a pending object. Common usage example:

deferred.promise.then(success_callback, error_callback)

When deferred.resolve() / deferred.reject(), this is normal, there is no memory leak because success_callback or error_callback was executed. But now I want to destroy the promise object, which means that I do not want to call deferred.resolve()or deferred.reject(), without a memory leak. How can i do this?

EDIT: More clearly, I want to ignore the existing promise, I don’t want success_callbackor to be error_callbackfulfilled anymore. Yes, maybe I want to cancel callbacks.

+4
source share
1 answer
delete deferred.promise

It is difficult to create memory leaks in JS, since it has automatic memory cleaning; this mainly happens, these are two objects that refer to each other, but do not have references to themselves one after another.

-1
source

All Articles