stackrefleak.nim 530 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. outputsub: "no leak: "
  3. """
  4. type
  5. Cyclic = object
  6. sibling: PCyclic
  7. data: array[0..200, char]
  8. PCyclic = ref Cyclic
  9. proc makePair: PCyclic =
  10. new(result)
  11. new(result.sibling)
  12. when not defined(gcDestructors):
  13. result.sibling.sibling = result
  14. proc loop =
  15. for i in 0..10000:
  16. var x = makePair()
  17. GC_fullCollect()
  18. x = nil
  19. GC_fullCollect()
  20. if getOccupiedMem() > 300_000:
  21. echo "still a leak! ", getOccupiedMem()
  22. quit(1)
  23. else:
  24. echo "no leak: ", getOccupiedMem()
  25. loop()