1 public class NativeWeakRef {
2 public native static void setWeakReference(Object o);
3 public native static Object getWeakReference();
4 public native static void delWeakReference();
6 public static void main(String args[]) {
8 System.loadLibrary("native");
10 /* create the object we want to deal with */
11 o = new String("I am not important, you can forget me!");
13 /* pass the object to the native world */
16 /* is the object still there? */
17 o = getWeakReference();
18 System.out.println(o);
20 /* now forget about it and see if it gets collected */
24 /* is the object still there? */
25 o = getWeakReference();
26 System.out.println(o);
28 /* delete the reference inside the native world */