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]

Re: valgrind and CNI


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

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.
>


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