Fix java binding to reflect new api
diff --git a/bindings/java/capstone/Capstone.java b/bindings/java/capstone/Capstone.java
index f394853..8f9a440 100644
--- a/bindings/java/capstone/Capstone.java
+++ b/bindings/java/capstone/Capstone.java
@@ -167,7 +167,7 @@
         break;
       default:
     }
-    return new cs_insn(insn, pointer, csh, cs, op_info);
+    return new cs_insn(insn, pointer, ns.csh, cs, op_info);
   }
 
   private cs_insn[] fromArrayPointer(Pointer pointer, int numberResults)
@@ -186,7 +186,7 @@
   private interface CS extends Library {
     public int cs_open(int arch, int mode, NativeLongByReference handle);
     public NativeLong cs_disasm_dyn(NativeLong handle, byte[] code, NativeLong code_len,
-        NativeLong addr, NativeLong count, PointerByReference insn);
+        long addr, NativeLong count, PointerByReference insn);
     public void cs_free(Pointer p);
     public int cs_close(NativeLong handle);
     public String cs_reg_name(NativeLong csh, int id);
@@ -226,29 +226,34 @@
   public static final int CS_ERR_CSH = 4;	    // Invalid csh argument
   public static final int CS_ERR_MODE = 5;	  // Invalid/unsupported mode
 
+  protected class NativeStruct {
+      private NativeLong csh;
+      private NativeLongByReference handleref;
+      private PointerByReference insnRef;
+  }
 
-  private NativeLong csh;
-  private PointerByReference insnRef;
+  protected NativeStruct ns; // for memory retention
   private CS cs;
 
   public Capstone(int arch, int mode)
   {
     this.arch = arch;
     this.mode = mode;
+    ns = new NativeStruct();
     cs = (CS)Native.loadLibrary("capstone", CS.class);
-    NativeLongByReference handleref = new NativeLongByReference();
-    if (cs.cs_open(arch, mode, handleref) != CS_ERR_OK) {
+    ns.handleref = new NativeLongByReference();
+    if (cs.cs_open(arch, mode, ns.handleref) != CS_ERR_OK) {
       throw new RuntimeException("ERROR: Wrong arch or mode");
     }
-    csh = handleref.getValue();
+    ns.csh = ns.handleref.getValue();
   }
 
   public String reg_name(int reg) {
-    return cs.cs_reg_name(csh, reg);
+    return cs.cs_reg_name(ns.csh, reg);
   }
 
   protected void finalize() {
-    cs.cs_close(csh);
+     cs.cs_close(ns.csh);
   }
 
   public cs_insn[] disasm(byte[] code, long address) {
@@ -256,11 +261,11 @@
   }
 
   public cs_insn[] disasm(byte[] code, long address, long count) {
-    insnRef = new PointerByReference();
+    ns.insnRef = new PointerByReference();
 
-    NativeLong c = cs.cs_disasm_dyn(csh, code, new NativeLong(code.length), new NativeLong(address), new NativeLong(count), insnRef);
+    NativeLong c = cs.cs_disasm_dyn(ns.csh, code, new NativeLong(code.length), address, new NativeLong(count), ns.insnRef);
 
-    Pointer p = insnRef.getValue();
+    Pointer p = ns.insnRef.getValue();
     cs_insn[] all_insn = fromArrayPointer(p, c.intValue());
     return all_insn;
   }