Skip to content

Instantly share code, notes, and snippets.

@zielmicha
Created December 4, 2013 20:47
Show Gist options
  • Save zielmicha/7795223 to your computer and use it in GitHub Desktop.
Save zielmicha/7795223 to your computer and use it in GitHub Desktop.
Destructors don't work on objects allocated by new :(
type
TThing = object
a: int
PThing = ref TThing
proc destruct1(instance: var TThing) {.destructor.} =
echo "destory TThing number ", instance.a
block:
var a: TThing = TThing(a: 2)
# prints "destory TThing number 2"
var a: PThing
new(a)
a.a = 3
a = nil
# should print now "destroy TThing number 3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment