tcycle1.nim 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. discard """
  2. output: "MEM 0"
  3. cmd: "nim c --gc:orc $file"
  4. """
  5. type
  6. Node = ref object of RootObj
  7. le, ri: Node
  8. name: char
  9. proc edge(a, b: Node) =
  10. if a.le == nil: a.le = b
  11. else: a.ri = b
  12. proc createNode(name: char): Node =
  13. new result
  14. result.name = name
  15. #[
  16. +---------+ +------+
  17. | | | |
  18. | A +----->+ <------+-------------+
  19. +--+------+ | | | |
  20. | | | | C |
  21. | | R | | |
  22. +--v------+ | | +-------------+
  23. | | | | ^
  24. | B <------+ | |
  25. | | | +--------+
  26. +---------+ | |
  27. +------+
  28. ]#
  29. proc main =
  30. let a = createNode('A')
  31. let b = createNode('B')
  32. let r = createNode('R')
  33. let c = createNode('C')
  34. a.edge b
  35. a.edge r
  36. r.edge b
  37. r.edge c
  38. c.edge r
  39. let mem = getOccupiedMem()
  40. main()
  41. GC_fullCollect()
  42. echo "MEM ", getOccupiedMem() - mem