How to exit out of the Java code when going back to the C++ code?
I wrote a program in Java and made it a plugin for Adobe Photoshop, which is written in C++ and calls my Java program using JNI.
In my C++ program I call JNI_CreateJavaVM, and I open a Java window with the same picture as in Photoshop and I minimize Photoshop.
Unfortunately when I go back and forth between the Photoshop and the Java window, it crashes about the 12th time I try to open the Java window, probably because a memory leak.
I was told not to use DestroyJavaVM in my C++ code. And in my Java code I cannot call System.exit(0) (which causes an immediate crash), but I would like to exit as much as possible to avoid the crash described above.
How can I do that?
Thanks for looking at this!
# 1
DestroyJavaVM does nothing in the Sun VM.
Obviously the solution would be to fix the leak.
But you could always spin up a process using the appropriate C/C++ api for your OS rather than using JNI. That would be easier to debug. You would have to deal with data transfer between the different processes but sockets, command line params, files, etc would solve that.
That solution would be easier to debug, more stable and it wouldn't require that you fix the leak.
# 2
That sounds great! And yes, I am pretty desperate to solve this, because it seems to be the last bug before my final release.
I am using Microsoft Windows XP Professional, but I do not know what my customers will use.
I am a total beginner in using the C/C++ api for my OS and in using sockets. Could you please give me some explanations (or examples) or give me a reference where I can find these explanations?
Thanks a lot!
# 3
> That sounds great! And yes, I am pretty desperate to
> solve this, because it seems to be the last bug
> before my final release.
>
> I am using Microsoft Windows XP Professional, but I
> do not know what my customers will use.
>
That is rather non-sensical from the point of view of JNI. You have to create a JNI shared library for a specific OS. So unless you intended to create them for a number of different systems then JNI wouldn't have solved anything.
Nor will another solution.
> I am a total beginner in using the C/C++ api for my
> OS and in using sockets. Could you please give me
> some explanations (or examples) or give me a
> reference where I can find these explanations?
Then use a file.
At any rate you can look a Runtime.exec(). Note that any solution via this mechanism is also OS specific.
# 4
Ok, I am starting to learn about sockets for communicating between my C++ code and my Java code
I can see how I can easily manage getting the picture pixels from Photoshop to my plugin and how I can communciate path data between Photoshop and my plugin with sockets.
However when I created the JVM in the C++ code, I also called the main method in the Java code from the C++ code. How could I do that with sockets or with a file?
Thanks for any help!