node.js - Node javascript recurse out of memory -


i'm doing simple recurse node generate strings of 10 characters. i've memory leak during execution. code below. ideas ?

i think may linked console.log(word) line. without line, code seems work. however, instead if printing result screen, final goal achieve http request generated word. i've tried without screen printing , generates out of memory well.

var char = [     'a',     'b',     'c',     'd',     'e',     'f',     'g',     'h',     'i',     'j',     'k',     'l',     'm',     'n',     'o',     'p',     'q',     'r',     's',     't',     'u',     'v',     'w',     'x',     'y',     'z',     ' ',     '\'' ];   function recurseword( keyword ){      if ( keyword.length >= 10 ){         return null ;     }     else{         ( var index = 0 ; index < char.length ; ++index){              keyword = keyword + char [index];              console.log (keyword);              recurseword (keyword) ;              keyword = keyword.substring(0, keyword.length-1);          }     }     return null ; }  var keyword = ""; recurseword(keyword); 

first of need move recursive call out of loop. otherwise loop never exit because index stay @ 0.

function recurseword( keyword ){          console.log (keyword);     if ( keyword.length >= 10 ){         return null ;     }     else{         ( var index = 0 ; index < char.length ; index++){              keyword = keyword + char [index];              console.log ("index "+index);          }         keyword += recurseword(keyword.substring(0, keyword.length-1));     }     return null ; } 

Comments