Created
March 22, 2014 09:12
-
-
Save Skrylar/9703599 to your computer and use it in GitHub Desktop.
Demonstrating how cyclic references which are both made weak will result in a GC crash.
This file contains hidden or 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 | |
RPizza = ref Pizza | |
Pizza = object | |
Backref: RPizza | |
proc NoPizza(self: RPizza) = | |
debugEcho "Pizza eaten by ghosts." | |
proc main() = | |
var x: RPizza | |
new(x, NoPizza) | |
var y: RPizza | |
new(y, NoPizza) | |
x.backref = y | |
y.backref = x | |
GCUnref(y) | |
GCUnref(x) | |
main() | |
GCFullCollect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment