gcleak.nim 568 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. outputsub: "no leak: "
  3. """
  4. when defined(GC_setMaxPause):
  5. GC_setMaxPause 2_000
  6. type
  7. TTestObj = object of RootObj
  8. x: string
  9. proc makeObj(): TTestObj =
  10. result.x = "Hello"
  11. const numIter =
  12. # see tests/gc/gcleak2.nim
  13. when defined(boehmgc):
  14. 1_000
  15. elif defined(gcMarkAndSweep): 10_000
  16. else: 100_000
  17. for i in 1 .. numIter:
  18. when defined(gcMarkAndSweep) or defined(boehmgc):
  19. GC_fullcollect()
  20. var obj = makeObj()
  21. if getOccupiedMem() > 300_000: quit("still a leak!")
  22. # echo GC_getstatistics()
  23. echo "no leak: ", getOccupiedMem()