Android memory leak with java code



  • Good day I have java code thats called with a string that returns a string. I based everything on the androidToastJava example I found online. I include here what I believe to be the relevent parts.

    The c++:
    QString get_CA( QString channel_name)
    {
    QAndroidJniObject tstMsg = QAndroidJniObject::fromString(channel_name);

    QAndroidJniObject RcvMsg = QAndroidJniObject::callStaticObjectMethod
    ("com/amin/QtAndroidToastJava/QtAndroidToastJava"
    , "get_CA"
    , "(Ljava/lang/String;)Ljava/lang/String;"
    , tstMsg.object<jstring>());
    return RcvMsg.toString();
    }

    In MainWindow::timerEvent( QTimerEvent *event ){
    ...
    // call the java code that gets altitude data
    altitude_pv = get_CA("altitude");
    altitude = altitude_pv.toFloat();
    qDebug() << "altitude = " << get_CA( "altitude");
    }

    The java, gets a data from an EPICS ioc via channel access:
    public static String get_CA(String pv) {
    // execute
    System.setProperty("CA_DISABLE_REPEATER", "false");
    System.setProperty("jca.use_env", "false");
    System.setProperty("com.cosylab.epics.caj.CAJContext.addr_list", "192.168.36.10");
    //String value = new QtAndroidToastJava().execute(pv);
    String value = thisInstance.execute(pv);
    return ( value );
    }

    Application output I see memory usage constantly going up but it is reading data
    D libqfi_example.so: altitude = "61017.47"
    I art : Background sticky concurrent mark sweep GC freed 18976(962KB) AllocSpace objects, 8(160KB) LOS objects, 11% free, 37MB/42MB, paused 16.653ms total 97.180ms
    D libqfi_example.so: altitude = "61017.47"
    D libqfi_example.so: altitude = "61017.47"
    I art : Background partial concurrent mark sweep GC freed 9173(472KB) AllocSpace objects, 6(120KB) LOS objects, 29% free, 38MB/54MB, paused 13.333ms total 88.519ms
    D libqfi_example.so: altitude = "61017.47"
    D libqfi_example.so: altitude = "61017.47"

    finally:
    I art : Background partial concurrent mark sweep GC freed 23039(1164KB) AllocSpace objects, 8(160KB) LOS objects, 19% free, 64MB/80MB, paused 17.837ms total 163.092ms
    D libqfi_example.so: altitude = "61017.47"
    D libqfi_example.so: altitude = "61017.47"
    W art : Large object allocation failed: ashmem_create_region failed for 'large object space allocation': Too many open files
    I art : Starting a blocking GC Alloc
    I art : Starting a blocking GC Alloc
    I art : Alloc sticky concurrent mark sweep GC freed 63819(3MB) AllocSpace objects, 19(380KB) LOS objects, 15% free, 68MB/80MB, paused 22.973ms total 154.361ms
    W art : Large object allocation failed: ashmem_create_region failed for 'large object space allocation': Too many open files
    W art : Throwing OutOfMemoryError "Failed to allocate a 65563 byte allocation with 16777216 free bytes and 187MB until OOM"
    I art : WaitForGcToComplete blocked for 384.454ms for cause HeapTrim
    E art : ashmem_create_region failed for 'indirect ref table': Too many open files
    W art : Throwing OutOfMemoryError "Could not allocate JNI Env"
    System.err: java.lang.OutOfMemoryError: Could not allocate JNI Env

    Im not sure whats causing this other then the multiple calls to java to get the data.
    What can I do to free up the memory?

    thx
    0



  • The java code had a memory leak in the code:
    public String execute(String channelName) {
    // String [] value = new String[50];
    double [] pv_data = new double[50];
    try {
    // initialize context
    //initialize();
    Context context = null;
    JCALibrary jca = JCALibrary.getInstance();
    context = jca.createContext(JCALibrary.CHANNEL_ACCESS_JAVA);
    // Create the Channel to connect to the PV.
    Channel channel = context.createChannel(channelName);
    ....
    ....
    ....
    // calling this before returning solved issue
    context.destroy();



  • The java code had a memory leak in the code:
    public String execute(String channelName) {
    // String [] value = new String[50];
    double [] pv_data = new double[50];
    try {
    // initialize context
    //initialize();
    Context context = null;
    JCALibrary jca = JCALibrary.getInstance();
    context = jca.createContext(JCALibrary.CHANNEL_ACCESS_JAVA);
    // Create the Channel to connect to the PV.
    Channel channel = context.createChannel(channelName);
    ....
    ....
    ....
    // calling this before returning solved issue
    context.destroy();


Log in to reply