type MyObject = ref object of RootRef
i: int
proc finalizeObject*[T](o: T) =
echo "finalizerCalled"
proc newMyObject*(): MyObject =
new(result, finalizeObject)
proc main =
var x = newMyObject()
x.i = 7
echo x.i * 2
main()
GC_FullCollect()
Run
$ nim c t.nim
$ ./t
14
Run
$ nim c -d:release t.nim
finalizerCalled
Run
$ nim -v
Nim Compiler Version 0.18.1 [Linux: amd64]
Compiled at 2018-08-20
Copyright (c) 2006-2018 by Andreas Rumpf
git hash: b75808c7d992ea47f8d6abc656b881b2aa0f86de
active boot switches: -d:release
Run
- Some fun with GC Stefan_Salewski
- Re: Some fun with GC Araq
- Re: Some fun with GC Stefan_Salewski
- Re: Some fun with GC Araq
- Re: Some fun with GC Stefan_Salewski
- Re: Some fun with GC Araq
- Re: Some fun with GC guy
- Re: Some fun with GC Araq
- Re: Some fun with GC Aiesha_Nazarothi
- Re: Some fun with GC boia01
- Re: Some fun with GC guy
