gcleak2.nim 885 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. s: seq[int]
  10. proc makeObj(): TTestObj =
  11. result.x = "Hello"
  12. result.s = @[1,2,3]
  13. const numIter =
  14. when defined(boehmgc):
  15. # super slow because GC_fullcollect() at each iteration; especially
  16. # on OSX 10.15 where it takes ~170s
  17. # `getOccupiedMem` should be constant after each iteration for i >= 3
  18. 1_000
  19. elif defined(gcMarkAndSweep):
  20. # likewise, somewhat slow, 1_000_000 would run for 8s
  21. # and same remark as above
  22. 100_000
  23. else: 1_000_000
  24. proc inProc() =
  25. for i in 1 .. numIter:
  26. when defined(gcMarkAndSweep) or defined(boehmgc):
  27. GC_fullcollect()
  28. var obj: TTestObj
  29. obj = makeObj()
  30. if getOccupiedMem() > 300_000: quit("still a leak!")
  31. inProc()
  32. echo "no leak: ", getOccupiedMem()