473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

jvm memory leak

Hi All,

My application calls some java functionalities using C++. While running, my application crashes after 1 hour. The reason it saya is "Java: Heap memory exhausted", it couldn't allocate heap memory for further operations as it was exhausted. I think, java uses garbage collector to release memory when ever the objects goes out of scope. I even tried to catch the exception,but, It was not caught. Could any one give me solutions to catch the exception or to free up the memory which the java holds up?
Dec 13 '07 #1
2 4117
How are you connecting to java from C++? JNI?The garbage collector will collect garbage when there is no longer a pointer to that object in your program. Check to make sure you are not retaining references anywhere (such as Vectors, Arrays, ect). Also if you are using JNI, as I understand it anything used in JNI call will not be dealt with by the garbage collector, and must be freed in C, I could be wrong on the specifics of this, but nothing allocated in C will be dealt with. If you are using something other than JNI, and are not retaining references, I expect the leak is coming from your C++ code, and java just happens to be what tries to allocate memory when it runs out. I've found valgrind helpful for finding memory leaks in C.
Dec 14 '07 #2
I too am experiencing a similar situation where I’m invoking the JNI interface from C++.

From C++ I’m invoking via (parts of the code renamed for simplicity):


JavaVMInitArgs vm_args;
JavaVMOption vm_options[3];
vm_options[0].optionString = "-Xms512M";
vm_options[1].optionString = "-Xmx1024M";
char* class_path_option = "-Djava.class.path="jar1.jar;jar2.jar;jar3;jar4.jar" );
vm_options[2].optionString = class_path_option;
vm_args.version = JNI_VERSION_1_4;
vm_args.options = vm_options;
vm_args.nOptions = 3;
vm_args.ignoreUnrecognized = JNI_FALSE;
jint create_vm_result = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

Then the class and method id are initialized:

javaClass = env->FindClass("com/wf/tiff/TiffValidator");
javaMethodID = env->GetStaticMethodID(javaClass , "validateMetWellsFargoMinimumStandard", "([B[B)Z");

From there the call is made (loop) and though the inbound parameter array is “released” via the JNI interface spec, memory usage grows until and out of memory error occurs.

{loop called from outer method}
jint jFrontSize = (jint)frontImageSize;
jint jBackSize = (jint)backImageSize;
jbyteArray jFrontBuffer = env->NewByteArray(jFrontSize);
jbyteArray jBackBuffer = env->NewByteArray(jBackSize);
jbyte* frontImagePtr = (jbyte*)frontImage;
jbyte* backImagePtr = (jbyte*)backImage;
env->SetByteArrayRegion(jFrontBuffer, 0, jFrontSize, frontImagePtr);
env->SetByteArrayRegion(jBackBuffer, 0, jBackSize, backImagePtr);
jboolean result = (jboolean) env->CallStaticObjectMethod(javaClass, javaMethodID, jFrontBuffer, jBackBuffer);
env->ReleaseByteArrayElements(jFrontBuffer, frontImagePtr, 0);
env->ReleaseByteArrayElements(jBackBuffer, backImagePtr, 0);

1) Is this similar to what your are seeing?
2) Any thoughts on how this may be resolved?

Thanks for your input!!
Jan 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
4
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
7
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.