valgrind and CNI
Andrew Haley
aph@redhat.com
Mon Feb 14 20:24:00 GMT 2005
David Blasby writes:
> I wrote a few example programs and the garbage collector seemed to be
> doing exactly what it was supposed to do.
>
> See the "memory management" section at the bottom of this wiki:
>
> http://docs.codehaus.org/display/GEOS/Compiling+JTS
This is because:
> > it conservatively scans the stack.
Andrew.
>
> Thanks,
> dave
>
> > > I was originally using valgrind to make sure that GCJ wasnt garbage
> > > collecting my Java objects when I passed them from C++ to C. For
> > > example, I use Geometry.h (created using gcjh) in the C++ library, but
> > > a "typedef struct Geometry Geometry;" in the "C" program.
> > >
> > > Java creates an Object, hands it off to the C++ library as a Geometry*
> > > class, then gets passed as a pointer to the "C" program. I thought
> > > the garbage collector might collect the java object between the time
> > > it leaves the C++ library and arrives at the "C" program.
> >
> > It might. gcj allocates its own objects, and only scans items
> > reachable from its roots. In addition, it conservatively scans the
> > stack. If you want to ensure that a gcj object is not reclaimed, you
> > should make very sure that it is reachable from a Java object
> > somewhere: this is as easy as declaring a static reference in some
> > Java class and pointing it at the object you want not to be reclaimed.
> >
> > Andrew.
> >
More information about the Java
mailing list