简体   繁体   中英

what are weak global references ? How it is different from a global reference?

What are weak global references in JNI ? How it is different from a global reference and a local reference ?

I think that the answer to your questions can be found here: http://java.sun.com/docs/books/jni/html/refs.html

As its written:

Local and global references have different lifetimes. Local references are automatically freed, whereas global and weak global references remain valid until they are freed by the programmer.

The difference between local references and global references is: the context

The local reference is just a local variable. The underlying object will be destroyed once you get out of its context (like returning from the native function that defined it).

Like global references, weak global references remain valid across native method calls and across different threads. Unlike global references, weak global references do not keep the underlying object from being garbage collected.

The difference between weak global references and global references is that the object referenced by the weak one can be garbaged collected if needed (in case of lack of memory).

If an object only have a weak reference the gc can clear it out from the memory.

The soft reference is mean a reference what doesn't prevent the gc when it's want to clear out the object too. But if an object referred by a soft reference the gc try keep the object in the memory while it's possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM