mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
fixes #376
This commit is contained in:
33
tests/gc/closureleak.nim
Normal file
33
tests/gc/closureleak.nim
Normal file
@@ -0,0 +1,33 @@
|
||||
discard """
|
||||
outputsub: "true"
|
||||
"""
|
||||
|
||||
from strutils import join
|
||||
|
||||
type
|
||||
TFoo * = object
|
||||
id: int
|
||||
func: proc(){.closure.}
|
||||
var foo_counter = 0
|
||||
var alive_foos = newseq[int](0)
|
||||
|
||||
proc free*(some: ref TFoo) =
|
||||
#echo "Tfoo #", some.id, " freed"
|
||||
alive_foos.del alive_foos.find(some.id)
|
||||
proc newFoo*(): ref TFoo =
|
||||
new result, free
|
||||
|
||||
result.id = foo_counter
|
||||
alive_foos.add result.id
|
||||
inc foo_counter
|
||||
|
||||
for i in 0 .. <10:
|
||||
discard newFoo()
|
||||
|
||||
for i in 0 .. <10:
|
||||
let f = newFoo()
|
||||
f.func = proc =
|
||||
echo f.id
|
||||
|
||||
gc_fullcollect()
|
||||
echo alive_foos.len <= 2
|
||||
23
tests/js/test2.nim
Normal file
23
tests/js/test2.nim
Normal file
@@ -0,0 +1,23 @@
|
||||
discard """
|
||||
cmd: "nimrod js --hints:on -r $# $#"
|
||||
output: '''foo
|
||||
js 3.14'''
|
||||
"""
|
||||
|
||||
# This file tests the JavaScript generator
|
||||
|
||||
# #335
|
||||
proc foo() =
|
||||
var bar = "foo"
|
||||
proc baz() =
|
||||
echo bar
|
||||
baz()
|
||||
foo()
|
||||
|
||||
# #376
|
||||
when not defined(JS):
|
||||
proc foo(val: float): string = "no js " & $val
|
||||
else:
|
||||
proc foo(val: float): string = "js " & $val
|
||||
|
||||
echo foo(3.14)
|
||||
@@ -131,6 +131,7 @@ proc runGcTests(r: var TResults, options: string) =
|
||||
test "gcleak3"
|
||||
test "weakrefs"
|
||||
test "cycleleak"
|
||||
test "closureleak"
|
||||
|
||||
# ------------------------- threading tests -----------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user