1 public class NativeGlobalRef {
2 public native static void setReference(Object o);
3 public native static Object getReference();
5 public static void main(String args[]) {
7 System.loadLibrary("native");
9 /* create the object we want to deal with */
10 o = new String("I am an important object, don't forget me!");
12 //for (int i=0; i<100; i++)
13 // s = s + "I am an important object, don't forget me!";
17 /* pass the object to the native world */
20 /* now forget about it and see if it gets collected */
24 /* fill up the heap */
25 //for (long i=0; i<100000000l; i++)
26 // o = new String("I am simply an heap filler!");
28 /* is the object still there? */
30 System.out.println(o);