Skip to content

Instantly share code, notes, and snippets.

@aoiroaoino
Created October 5, 2019 18:11
Show Gist options
  • Select an option

  • Save aoiroaoino/0217f34e8dff1cc109d436dcfde3b820 to your computer and use it in GitHub Desktop.

Select an option

Save aoiroaoino/0217f34e8dff1cc109d436dcfde3b820 to your computer and use it in GitHub Desktop.
import scala.language.existentials
import java.net._
var loader = new URLClassLoader(Array(new URL("file:///tmp/example/")))
val wrCat = new java.lang.ref.WeakReference(loader.loadClass("example.Cat"))
println("=== class cat: " + wrCat.get)
println("~~~ remove loader ~~~")
loader = null
System.gc()
println("=== class cat: " + wrCat.get)
println("")
/*
=== class cat: class example.Cat
~~~ remove loader ~~~
=== class cat: null
*/
@aoiroaoino
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment