1 public class NativeGlobalRef {
2 public native static void setReference(Object o);
3 public native static Object getReference();
4 public native static void delReference();
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 an important object, don't forget me!");
13 //for (int i=0; i<100; i++)
14 // s = s + "I am an important object, don't forget me!";
18 /* pass the object to the native world */
21 /* now forget about it and see if it gets collected */
25 /* fill up the heap */
26 //for (long i=0; i<100000000l; i++)
27 // o = new String("I am simply an heap filler!");
29 /* is the object still there? */
31 System.out.println(o);
33 /* delete the reference inside the native world */