This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Finalization and CNI


Hello All:

I am getting started with CNI programming and I have a question.  I am a
seasoned JNI programmer getting into CNI for the first time and I have
some questions about memory management.

The main question is simply this - how does it work?  Let's say, for
example, that I have the following CNI program:

HelloWorld.java:
class HelloWorld {
  public native void print();
  public static void main(String[] args) {
    HelloWorld hw = new HelloWorld();
    hw.print();
    System.out.println("Hello World: DONE");
  }
}

include <gcj/cni.h>
#include <stdio.h>
#include "HelloWorld.h"

void HelloWorld::print() {
  printf("Hello, world from CNI!\n");

  void *alloc = new char[1024];
}

Presumably "alloc" is going to be leaked, correct?  Is the correct thing
to do to put the deallocation stuff into the destructor for the
HelloWorld class?  Would my destructor then get called at some point?

Any words about how memory management works in the CNI world would be
greatly appreciated.  Any pointers to docs, etc. would be nice also
because I have not been able to find much on this topic.

TIA
craig vanderborgh
voxware incorporated




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]