Created
December 4, 2013 20:47
-
-
Save zielmicha/7795223 to your computer and use it in GitHub Desktop.
Destructors don't work on objects allocated by new :(
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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