javascript - recursive calls to ajax cause memory leak? -
does following code logic cause original call's stack frame contain memory each subsequent call (causing excessive memory usage)?
function foo (arg) {     bar(arg); }  function bar (arg) {   $.ajax({      success: function (data) {          if (data['result'] == 'continue') {             bar(data['nextarg']);          } else if (data['result'] == 'done') {             alert('done!');          }      }   }); }      
your code not recursive. $.ajax asynchronous, stack pointer isn't waiting bar return.
instead, $.ajax fires asynchronous process, continues until hits either explicit or implicit return. in case, there implicit return @ end of bar.
your function consumes no more memory should.
function bar (arg) {   // calls $.ajax, async, fires "whenever"   $.ajax({     // when ajax complete/successful, function called       success: function (data) {          if (data['result'] == 'continue') {             bar(data['nextarg']);          } else if (data['result'] == 'done') {             alert('done!');          }      }   })   // exits after }      
Comments
Post a Comment