简体   繁体   中英

Domino JVM memory and POI

I have an agent which exports notes document to excel (xlsm) using Apache POI. I am following every possible way to release memory by using recycle() or setting up objects to null.However, JVM still goes out of heap size and throws "Out of memory" error. Here are some more info,

  • Default heapsize=256MB
  • POI version - 3.17
  • How frequent error comes? If I run the agent from the web 5-6 times continuously.
  • xlsm template size : 90 kb
  • Number of records writing - 10-30

Another thing I am observing but unable to understand is how JVM using/releasing memory. For example, I am printing "available" memory before the code starts and after the code ends using following code,

Runtime runtime = Runtime.getRuntime();
double usedMemory = usedMemory(runtime);

System.out.println("START - Initial memory :: " + String.valueOf(usedMemory) )

static double usedMemory(Runtime runtime) {
        long totalMemory = runtime.totalMemory();
        long freeMemory = runtime.freeMemory();
        double usedMemory = (double)(totalMemory - freeMemory) / (double)(1024 * 1024);
        return usedMemory;
    }

When I test my agent very first time it' prints like,

JVM START : Initial memory available : 60 MB

JVM END : Used memory : 90 MB

Second time when agent starts it prints,

JVM START : Initial memory available : 130 MB

JVM END : Used memory : 160 MB

Even though I am releasing memory at the end of the code, I see it doesn't goes down to initial memory ( 60 MB ) ?

        /* Free up memory */
        webDoc.recycle();
        docA.recycle();
        vwLookup.recycle();
        curDb.recycle(); 
        session.recycle(); 

        agentContext=null;

        fpath.delete();
        xlFile.delete();

        runtime = Runtime.getRuntime();
        usedMemory = usedMemory(runtime);

        System.out.println("END - MAIN :: Total used memory: " + String.valueOf(usedMemory) );

        freeMemory();

I've opened a PMR regarding this issue last year. The answer of IBM was as follows:

I would like to inform you that this is a know limitation with attached jar files to the agent or script libraries. See below some of the SPRs reporting the issue:

SPR # BHUY8VML6R: "Customer Is Experiencing Ongoing Memory Leak Only When Jar Files Are Attached To The Agent In The Database"

SPR # BHUY8PRMKK: "Java Memory Leak When Using Attached Jar Files To The Agent Or Script Libraries."

SPR # JSHN83MMMW: "Memory leak in Java agent with attached JAR file"

The only workaround available is as follows: Remove the JAR file from the project of the Java Agent and place it in the jvm/lib/ext folder or reference it by notes.ini parameter JavaUserClasses."

I know it's not that what do you want to hear... but theses are the facts. Since then, I use OSGi plugins wherever possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM