Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java thread: Problems unloading JVM from Visual Studio IDE


Message #1 by "Beata Chrulkiewicz" <moominek@h...> on Thu, 5 Sep 2002 19:21:04
Hi,

I have a COM object that is calling some java functions through JNI. I am 
using my COM object in the VB code. When I run the executive that I create 
from my VB, everything works fine. When I try to run my code in the Visual 
Studio debugger, it seems to run just fine, but if I exit the debugger and 
try to execute the program again, my whole IDE just disappears. Not even 
an error message. 

I did some more research and I found that DestroyJavaVM does not actually
unload the virtual machine. The virtual machine does not get unloaded until
the process that created it terminates. I noticed that when I run my vb
program in the IDE, a new process is not created, so I guess it is
actually the VB6.exe that starts the java machine. I am guessing here that 
the Java VM does not really get unloaded when I exit the debugger, and 
when I try to start it again, the VM gets terminated together with the 
process that started it. Which is my Visual Studio IDE.

I did a  little experiment, where I changed my COM code not to unload the
virtual machine. This time everything worked fine, only now I have a memory
leak, because I cannot release the jvm pointer without destroying the
JavaVM. So I cannot leave it like that.

I tried to use JNI_GetCreatedJavaVMs function to check if there is a 
virtual machine previously created, but it returns 0 even if I think 
something should be running. Is it returning only virtual machines created 
by the same process?

Does anybody have an idea on how to deal with this problem? I have no idea 
on how to approach the problem now. I even tried System.exit to kill the 
java, but that also kills the process that started it, which is the IDE, 
so I am back to square one. 

ANY hints will be greatly appreciated, as I am at my wits end trying to 
solve this problem.

Thanks,

Beata


  Return to Index