When and how are ajax calls cleaned up after they are completed?

When and how are ajax calls cleaned up after they are completed?

Hi,

I noticed that if I pass a context object to the $.ajax function, that object will never be released, even after the ajax call has completed. For example, in the following code, object 'a' is never destroyed because the 'callbackcontext' object kept a reference to it. The same applies to the callback functions passed to the ajax call as well. I used Chrome's heap snapshot tool to check the existence of objects.

It seems unnecessary to keep those callback functions and callbackcontext objects around after the ajax request has completed, and it causes memory leaks. Is this by design, or am I missing something here? Are ajax requests cleaned up by jQuery or do I have to do that myself and how?

  1. var a;
  2. var options = {
  3.       context: a,
  4.       success: function {},
  5.       complete: function {}
  6. };
  7. $.ajax(options);