trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sureshsubbiah <>
Subject [GitHub] incubator-trafodion pull request #697: [TRAFODION-2218] Memory leak from JVM...
Date Wed, 14 Sep 2016 16:46:44 GMT
Github user sureshsubbiah commented on a diff in the pull request:
    --- Diff: core/sql/langman/LmRoutineJavaObj.cpp ---
    @@ -192,6 +192,7 @@ LmResult LmRoutineJavaObj::invokeRoutineMethod(
    +  jni->DeleteLocalRef(jniResult);
    --- End diff --
    I have been thinking about this more and talked to @zellerh.
    From JNI specs
    we have
    "Local References
    **Local references are valid for the duration of a native method call. They are freed
automatically after the native method returns.** Each local reference costs some amount of
Java Virtual Machine resource. Programmers need to make sure that native methods do not excessively
allocate local references. Although local references are automatically freed after the native
method returns to Java, excessive allocation of local references may cause the VM to run out
of memory during the execution of a native method."
    However in Trafodion's use of JNI, we know by debugging this JIRA that localRefs are never
freed, unless they are explicitly deleted. This must be because the "native" method never
returns, as the C++ side inits the JVM. Therefore in this use we delete the local Ref to ReturnInfo,
but we have new local refs to returnedIIL and returnedPIL. Those are deleted later after they
are used (when this method called next or in the destructor). Those 2 byte arrays will not
be GCed right after local ref to ReturnInfo is deleted, since there is one other local ref
pointing to each one of them. They will be GCed only when all localRefs pointing to them (including
parent class) are deleted. 

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

View raw message