Skip to content

Instantly share code, notes, and snippets.

@Bringoff
Created November 17, 2021 11:40
Show Gist options
  • Select an option

  • Save Bringoff/7401b06198a148757cf80a3c0fa89aff to your computer and use it in GitHub Desktop.

Select an option

Save Bringoff/7401b06198a148757cf80a3c0fa89aff to your computer and use it in GitHub Desktop.
Circular references
fun main(args: Array<String>) {
Inner().nodes()
readLine()
System.gc()
readLine()
}
class Inner {
fun nodes() {
val first = Node()
val second = Node()
first.child = second
second.child = first
}
}
class Node {
var child: Node? = null
protected fun finalize() {
println("${hashCode()} finalized")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment