Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74079

QAndroidJniObject issue with Java garbage collector

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.12.0
    • Extras: Android
    • None

      I have a Java class where I override the "finalize" method to know when that the Java object is eligible by garbage collector.

       

      class Foo {
          ...
          @Override
          protected void finalize (){
            Log.d(QtApplication.QtTAG, "#### FINALIZE ####");
          }
          ...
      }
      

       

       

      I create an new instance of this Java class with QAndroidJniObject and keep it as a member of my C++ class.

       

      Foo::Foo() 
      {
          m_javaObject = nullptr;
          QtAndroid::runOnAndroidThreadSync([&](){
              m_javaObject = new QAndroidJniObject(...);
          });
      }
      

       

      The problem is that I see the "finalize" log trace of the Java object after few calls on my object, so it means that the Java object could be garbage collected and it should not because I did not delete the pointer "m_javaObject".

      Am I missing something ?

       

       

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            esabraha Eskil Abrahamsen Blomfeldt
            apap_ Loic Martin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes