File: turn_destroy_into_finalizer.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (22 lines) | stat: -rw-r--r-- 272 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()