summary refs log tree commit diff stats
path: root/tests/gc/stackrefleak.nim
blob: 302ef35997f5dcabc2b896ad0ece342ce62c4504 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
discard """
  outputsub: "no leak: "
"""

type
  Cyclic = object
    sibling: PCyclic
    data: array[0..200, char]

  PCyclic = ref Cyclic

proc makePair: PCyclic =
  new(result)
  new(result.sibling)
  result.sibling.sibling = result

proc loop =
  for i in 0..10000:
    var x = makePair()
    GC_fullCollect()
    x = nil
    GC_fullCollect()

  if getOccupiedMem() > 300_000:
    echo "still a leak! ", getOccupiedMem()
    quit(1)
  else:
    echo "no leak: ", getOccupiedMem()

loop()