Java Object allocation from C++ and references?

Andrew Haley aph@redhat.com
Wed Feb 4 13:10:00 GMT 2004


Ben Martin writes:
 > On Wed, 2004年02月04日 at 00:40, Andrew Haley wrote:
 > > Ben Martin writes:
 > > > is it correct to assume that if one is to use C++ code and create an
 > > > object implemented in Java code, for example, java::lang::String, then
 > > > the C++ code creating the new String* does not call delete?
 > > 
 > > That's right.
 > > 
 > > > I have rolled rpms for jakarta-lucene using gcj from Fedora
 > > > development and using C++ smart pointers to manage
 > > > java::lang::string objects seems to work but when I use a C++ smart
 > > > pointer on one of the Lucene java objects the program crashes on
 > > > the delete of that object.
 > > 
 > > You mustn't do that. Let the garbage collector do the job.
 > 
 > Upon reflection, I think I may have been using reference counting for
 > too long for memory management. I'll assume that the GC will collect all
 > Java objects that are made irrespective of if they are constructed from
 > Java or C++ using CNI.
Well, that's true kinda-sorta. But the gc in libgcj only will collect
garbage that it created, and that means you'd better make sure that
your data is in Java classes that the gc knows about. Mixing C++
classes and gcj classes isn't impossible, but I'd not say it was a
good idea.
Andrew.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /