Java objects obtained by c++: are they garbage collected?

View: New views
4 Messages — Rating Filter:   Alert me  

Java objects obtained by c++: are they garbage collected?

by Yuri-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I compiled several Java classes into a shared library and call it's
methods from C++.
Some of these methods return Java objects.

I wonder do I have to do anything special about them in order for them
to get garbage collected?

Yuri

Re: Java objects obtained by c++: are they garbage collected?

by David Daney-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yuri wrote:
> I compiled several Java classes into a shared library and call it's
> methods from C++.
> Some of these methods return Java objects.
>
> I wonder do I have to do anything special about them in order for them
> to get garbage collected?
>

If you use the CNI facilities to start the runtime and do the calling,
everything should just work (including garbage collection).

David Daney

Re: Java objects obtained by c++: are they garbage collected?

by Yuri-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Daney wrote:

> Yuri wrote:
>> I compiled several Java classes into a shared library and call it's
>> methods from C++.
>> Some of these methods return Java objects.
>>
>> I wonder do I have to do anything special about them in order for
>> them to get garbage collected?
>>
>
> If you use the CNI facilities to start the runtime and do the calling,
> everything should just work (including garbage collection).

I initialize the runtime using CNI and call methods using dlsym + call
of that symbol.

Yuri

Re: Java objects obtained by c++: are they garbage collected?

by Glenn Chambers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-10-16 at 12:17 -0700, Yuri wrote:
> David Daney wrote:

> > If you use the CNI facilities to start the runtime and do the calling,
> > everything should just work (including garbage collection).
>
> I initialize the runtime using CNI and call methods using dlsym + call
> of that symbol.

I saved a bunch of previous messages on the subject in my e-mail folder.

Something that may be relevant to your situation:

Andre Haley wrote:

> I think a bit more clarification is required.
>
> If you get a reference to a Java object as a result of a function
> call, you must store that reference somewhere that is reachable by the
> collector or that object will be collected.  The collector scans all
> fields of all objects, so something like
>
>     MyClass::foo = objectRef;
>
> is sufficient.  Storing the reference in an object in the C++ heap
> will *not* do.