0

I have a search method called recursively via the callback method. Presumably this will not crash the code by overflowing the stack. Is there some way to prove that the memory is not growing exponentially when this method is run from the callback?

    var i=0; // global
    var l=arrNames.length;

    var cbfunc=function(err,record){
        console.log(record.data);
        if (++i<l){
            client.search(arrNames[i], cbfunc);
        }
    }

    // Presumably an async search method.
    client.search(arrNames[i],cbfunc);
user603749
  • 1,638
  • 2
  • 24
  • 36
  • As long as `client.search` is asynchronous, this can go on forever (without overflowing anything) – Bergi Sep 29 '15 at 16:01
  • @KevinB: I think that sentence refers to a *loop*, not a recursive function. – Bergi Sep 29 '15 at 16:03
  • ok i re-edited. please re-open. thanks – user603749 Sep 29 '15 at 17:30
  • What exactly do you mean by "proof"? If you're looking for a [formal verification](https://en.wikipedia.org/wiki/Formal_verification), then good luck - you also need to proof the garbage collector of your runtime (they'll be happy if you do!). If you just want to measure, let it run for some time and profile memory usage. See the docs of your dev tools. – Bergi Sep 29 '15 at 17:51

0 Answers0