diff options
author | Araq <rumpf_a@web.de> | 2019-11-22 17:18:01 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-11-22 17:18:11 +0100 |
commit | c85e266d1d6553fe14ecd28af7a58687672c859d (patch) | |
tree | 432006ba9396ff11a620e1207deec5dae5308c99 /tests/destructor | |
parent | f0c5d99924768175c332f412eb9c72ce5e28d0cb (diff) | |
download | Nim-c85e266d1d6553fe14ecd28af7a58687672c859d.tar.gz |
ARC: yet another silly bugfix
Diffstat (limited to 'tests/destructor')
-rw-r--r-- | tests/destructor/tarc2.nim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/destructor/tarc2.nim b/tests/destructor/tarc2.nim new file mode 100644 index 000000000..56dbfe929 --- /dev/null +++ b/tests/destructor/tarc2.nim @@ -0,0 +1,29 @@ +discard """ + output: '''leak: true''' + cmd: '''nim c --gc:arc $file''' +""" + +type + T = ref object + s: seq[T] + data: string + +proc create(): T = T(s: @[], data: "abc") + +proc addX(x: T; data: string) = + x.data = data + +proc addX(x: T; child: T) = + x.s.add child + +proc main(rootName: string) = + var root = create() + root.data = rootName + # this implies we do the refcounting wrong. We should leak memory here + # and not create a destruction cycle: + root.addX root + +let mem = getOccupiedMem() +main("yeah") +# since we created a retain cycle, we MUST leak memory here: +echo "leak: ", getOccupiedMem() - mem > 0 |