tlists.nim 954 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. output: '''Success'''
  3. """
  4. # bug #3793
  5. import os
  6. import math
  7. import lists
  8. import strutils
  9. proc mkleak() =
  10. # allocate 10 MB via linked lists
  11. let numberOfLists = 100
  12. for i in countUp(1, numberOfLists):
  13. var leakList = initDoublyLinkedList[string]()
  14. let numberOfLeaks = 50000
  15. for j in countUp(1, numberOfLeaks):
  16. let leakSize = 200
  17. let leaked = newString(leakSize)
  18. leakList.append(leaked)
  19. proc mkManyLeaks() =
  20. for i in 0..0:
  21. when false: echo getOccupiedMem()
  22. mkleak()
  23. when false: echo getOccupiedMem()
  24. # Force a full collection. This should free all of the
  25. # lists and bring the memory usage down to a few MB's.
  26. GC_fullCollect()
  27. when false: echo getOccupiedMem()
  28. if getOccupiedMem() > 8 * 200 * 50_000 * 2:
  29. echo GC_getStatistics()
  30. quit "leaking"
  31. echo "Success"
  32. mkManyLeaks()