Mark And Sweep Algorithm In Javascript