refarrayleak.nim 625 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. outputsub: "no leak: "
  3. retries: 2
  4. """
  5. type
  6. TNode = object
  7. data: array[0..300, char]
  8. PNode = ref TNode
  9. TNodeArray = array[0..10, PNode]
  10. TArrayHolder = object
  11. sons: TNodeArray
  12. proc nullify(a: var TNodeArray) =
  13. for i in 0..high(a):
  14. a[i] = nil
  15. proc newArrayHolder: ref TArrayHolder =
  16. new result
  17. for i in 0..high(result.sons):
  18. new result.sons[i]
  19. nullify result.sons
  20. proc loop =
  21. for i in 0..10000:
  22. discard newArrayHolder()
  23. if getOccupiedMem() > 300_000:
  24. echo "still a leak! ", getOccupiedMem()
  25. quit 1
  26. else:
  27. echo "no leak: ", getOccupiedMem()
  28. loop()