Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Advanced-java] JNI problem
- From: sumit@xxxxxxxxxxxxxxx (Indoria, Sumit (GMI NY - GDA))
- Subject: [Advanced-java] JNI problem
- Date: Mon, 25 Feb 2002 13:10:42 -0500
Hi!
I am having trouble doing some memory management in JNI, any ideas would be helpful.
Here is the structure
public class A
{
public A()
{
_jni_initialize(); // allocates a native instance of class A
}
protected void finalize()
{
_jni_delete();
}
private native _jni_initialize(); // allocates native C++ instance
private native _jni_delete()
private transient long Cinstance; // holds the memory address of the native C++ instance
}
public class B
extends A
{
public B()
{
_jni_initialize(); // allocates a native instance of class B
}
protected void finalize()
{
_jni_delete();
supre.finalize();
}
private native _jni_initialize(); // allocates native C++ instance
private native _jni_delete()
private transient long Cinstance; // holds the memory address of the native C++ instance
}
Now when i construct a B object, the A constructor is also called being a super class, and I have a native instance of both A and B allocated . Well conceptually when the finalize() method is called
on B , it should also call finalize() on the super A() and delete any native instance allocated, but this is where it fails, the B object gets deleted on the finalize call, but when I step through the
_jni_delete() of the class A, it has no idea about the native object created , when the constructor for B was called, so it basically returns me a null pointer exception. Any ideas why this behaviour
is occuring and any solutions to it.
(I tried a dirty solution of creating a dummy A constructor which does not allocate a native instance, and that works, but this seems really dirty... )
Thanks for your help.
Sumit
- Prev by Date: [Advanced-java] package for creation of graphs
- Next by Date: [Advanced-java] looking for web-based XML editor (w. Java source)
- Previous by thread: [Advanced-java] package for creation of graphs
- Next by thread: [Advanced-java] looking for web-based XML editor (w. Java source)
- Index(es):