summary refs log tree commit diff stats
path: root/tests/destructor/tlists.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-11-12 15:05:36 +0100
committerGitHub <noreply@github.com>2019-11-12 15:05:36 +0100
commitdfb020b174b6f3489294d9ec096de3cf9d6b5944 (patch)
tree30a5ef1faaa611c5de2d092d03c5cb12df0741b5 /tests/destructor/tlists.nim
parent7e689873e203620c3a14f1697129cd0e3fd548e4 (diff)
downloadNim-dfb020b174b6f3489294d9ec096de3cf9d6b5944.tar.gz
.cursor implementation (#12637)
* cursors: first implementation
* added currently failing test
* .cursor works for doubly linked lists
* make -d:useMalloc work again
* added code to nil out refs in a destructor
* it's now called --gc:arc
* renderer.nim: render nkBreakState properly
* make simple closure iterators work without leaking
Diffstat (limited to 'tests/destructor/tlists.nim')
-rw-r--r--tests/destructor/tlists.nim38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/destructor/tlists.nim b/tests/destructor/tlists.nim
new file mode 100644
index 000000000..7a81e602e
--- /dev/null
+++ b/tests/destructor/tlists.nim
@@ -0,0 +1,38 @@
+discard """
+  output: '''Success
+@["a", "b", "c"]
+0'''
+  cmd: '''nim c --gc:destructors $file'''
+"""
+
+import os
+import math
+import lists
+import strutils
+
+proc mkleak() =
+  # allocate 1 MB via linked lists
+  let numberOfLists = 100
+  for i in countUp(1, numberOfLists):
+    var leakList = initDoublyLinkedList[string]()
+    let numberOfLeaks = 5000
+    for j in countUp(1, numberOfLeaks):
+      leakList.append(newString(200))
+
+proc mkManyLeaks() =
+  for i in 0..0:
+    mkleak()
+  echo "Success"
+
+iterator foobar(c: string): seq[string] {.closure.} =
+  yield @["a", "b", c]
+
+proc tsimpleClosureIterator =
+  var myc = "c"
+  for it in foobar(myc):
+    echo it
+
+let startMem = getOccupiedMem()
+mkManyLeaks()
+tsimpleClosureIterator()
+echo getOccupiedMem() - startMem