Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Created March 22, 2014 09:12
Show Gist options
  • Save Skrylar/9703599 to your computer and use it in GitHub Desktop.
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.
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