/js/src/metrics/gc/tests/objGraph.js

http://github.com/zpao/v8monkey · JavaScript · 37 lines · 30 code · 7 blank · 0 comment · 4 complexity · 8811e13e5d5dc3355421d81cb901f263 MD5 · raw file

  1. test();
  2. function test()
  3. {
  4. function generate_big_object_graph()
  5. {
  6. var root = {};
  7. f(root, 17);
  8. return root;
  9. function f(parent, depth) {
  10. if (depth == 0)
  11. return;
  12. --depth;
  13. f(parent.a = {}, depth);
  14. f(parent.b = {}, depth);
  15. }
  16. }
  17. function f(obj) {
  18. with (obj)
  19. return arguments;
  20. }
  21. for(var i = 0; i != 10; ++i)
  22. {
  23. gc();
  24. var x = null;
  25. x = f(generate_big_object_graph());
  26. gc(); //all used
  27. x = null;
  28. gc(); //all free
  29. }
  30. }