summary refs log tree commit diff stats
path: root/tests/gc
diff options
context:
space:
mode:
authoralaviss <leorize+oss@disroot.org>2020-08-17 18:20:48 +0000
committerGitHub <noreply@github.com>2020-08-17 20:20:48 +0200
commite9df8ebcfd475a715756d24e1718a5c1455689d2 (patch)
tree06380aad49cddd8151f5a28dad8bbf6ca03ead3a /tests/gc
parent6feb3900b121a356a1c091855008d080223ea802 (diff)
downloadNim-e9df8ebcfd475a715756d24e1718a5c1455689d2.tar.gz
gc_regions: cleanup & fixes for deallocation (#11920)
* gc_regions: withRegion nows return the modified MemRegion

* gc_regions: make withScratchRegion dealloc correctly

* tests/gc: add tregionleak test

This test checks if memory within regions are freed properly.
Diffstat (limited to 'tests/gc')
-rw-r--r--tests/gc/tregionleak.nim23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/gc/tregionleak.nim b/tests/gc/tregionleak.nim
new file mode 100644
index 000000000..277cfc987
--- /dev/null
+++ b/tests/gc/tregionleak.nim
@@ -0,0 +1,23 @@
+discard """
+  cmd: '''nim c --gc:regions $file'''
+  output: '''
+finalized
+finalized
+'''
+"""
+
+proc finish(o: RootRef) =
+  echo "finalized"
+
+withScratchRegion:
+  var test: RootRef
+  new(test, finish)
+
+var
+  mr: MemRegion
+  test: RootRef
+
+withRegion(mr):
+  new(test, finish)
+
+deallocAll(mr)