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] | |
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.
This is initially the way I thought it would work. The only problem that
I saw that led my to question my initial thoughts are how does the JVM
know that the C++ pointer is still required or is not required?
Example
{
MyFoo* foo = new mytree::MyFoo();
MyBar* bar = new mytree::MyBar();
bar->methodname( foo );
// at this point foo & bar are "locked" by the C++ code,
// the GC can not collect them because I still have C++
// pointers to them and the JVM will have no way of knowing
// when those pointers drop out of C++ scope on the next code
// line so from my understanding the GC can never collect
// those objects. If the GC *does* collect them then a dereference
// of foo or bar which may happen next instead will do very bad
// things.
}
Sorry if this seems a trivial question, but I can't help but think there
are other newbie gcj users who would have the same question.
--
Blogtackular http://advogato.org/person/monkeyiq/
Attachment:
signature.asc
Description: This is a digitally signed message part
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |