Q:

How to set Heap Space for non executable JAR using JNI

Currently I am working on a mac application in which I am getting OutOfMemoryError frequently. Currently we are using non executable JAR file for our application so I cannot set heap size before starting my application because my java code will execute using JNI, So there is any possible way to set heap size using JNI or C. 
Or Any other solution for the above problem.
Thanks in Advance.

A:

I found the answer. I was using JNI so before creating JVM we must fill JavaVMOption parameter as "-Xms256m" for minimum size and "-Xmx512m" for maximum size. It will allocate minimum JVM heap size as 256 MB and maximum JVM heap size as 512 MB.
So this is the code to help others:
JavaVMInitArgs args;
JavaVMOption options[3];
args.nOptions = 3;

options[0] = (char*)"-Xms256m";
options[1] = (char*)"-Xmx512m";
options[2] = //Your JAR file path.
args.options = options;

Then pass args (JavaVMInitArgs object) while creating JVM. Above code will set minimum and maximum heap size. 
Remember 1 more thing do not set your minimum heap size before setting maximum heap size because in that case your minimum heap size will be more than or equal to maximum heap size and it will crash.

