turn destructors into finalizers
This commit is contained in:
parent
683c60e2fd
commit
9b31f67859
3 changed files with 40 additions and 6 deletions
22
tests/destructor/turn_destroy_into_finalizer.nim
Normal file
22
tests/destructor/turn_destroy_into_finalizer.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
discard """
|
||||
output: '''true'''
|
||||
"""
|
||||
|
||||
type
|
||||
Foo = object
|
||||
id: int
|
||||
|
||||
var destroyed: int
|
||||
|
||||
proc `=destroy`(x: var Foo) =
|
||||
#echo "finally ", x.id
|
||||
inc destroyed
|
||||
|
||||
proc main =
|
||||
var r: ref Foo
|
||||
for i in 1..50_000:
|
||||
new(r)
|
||||
r.id = i
|
||||
echo destroyed > 30_000
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue