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()
lor: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/env zsh
# Helper to more conveniently open commonly-used SubX programs.

if [ $# -eq 0 ]
then
  echo "Usage: $0 <file root without subdirectory or .subx extension>"
  echo
  echo "Naming convention: Files starting with 'ex' will be assumed to live in examples/"
  echo "Other files will be assumed to live in apps/"
  exit 1
fi

if [[ $EDITOR == *'vim'* ]]
then
  $EDITOR -S vimrc.vim apps/$1.subx
else
  $EDITOR              apps/$1.subx
fi