fix incorrect global ref removal, causing jvm to segfault when using multi threading