Java loads dll, causing Java Process Memory leakage

Source: Internet
Author: User

By zhaoch


During the performance test of the network monitoring system, memory leakage has occurred, which has been plagued for a long time. Now it is a solution, but the root cause is still unclear. Let's discuss it with you, see if it can be solved perfectly ~

This strange problem is caused by memory leakage of Java processes, rather than the normal JVM Memory leakage. The problem cannot be seen by tools such as Jprofile.

The test code is as follows:

1 System. loadLibrary ("test1 ");
2
3 int threadPoolSize = 400;
4 ExecutorService service = Executors. newFixedThreadPool (threadPoolSize );
5
6 for (int I = 0; I <400; I ++ ){
7 service. submit (new Runnable (){
8 public void run (){
9 while (true ){
10 try {
11 Thread t = new Thread ();
12 t. start ();
13 Thread. sleep (100 );
14} catch (Exception e ){
15 e. printStackTrace ();
16}
17}
18}
19 });
20}

Note: The job of this code segment is to load a dll and start the thread continuously (the thread stops directly without doing anything ).
Note: The thread pool is only used to accelerate the recurrence of the problem and is useless.

Symptom:
1. If the dll is not loaded, only the thread is continuously started. The memory of the Java Process is normal and will not keep increasing.
2. If the dll test1 in the attachment is loaded, the memory of the Java Process will keep increasing.
3. If you load the test2 dll in the attachment (you need to install the C ++ runtime environment vcredist_x86), the Java Process Memory is normal and will not continue to grow.

Dll description:
The dll project source code is included in the attachment. The difference between test1 and test2 lies only in the compilation options, such as the attachment: test1 selects "use standard Windows library" or "use MFC in static library", test2 selects "use MFC in shared DLL"
This dll project uses jni and introduces the mfc header file [# include <afxwin. h>]. If the mfc header file is not introduced, it will not cause memory leakage.


The root cause of this problem is unclear. I suspect it is a jdk bug (it is useless to use the latest jdk 1.6.0.23). Do you have any idea? Welcome to the discussion ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.