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

QML Loader is leaking memory on Rectangle and ShaderEffect reload

    XMLWordPrintable

Details

    • Linux/Wayland, Linux/X11

    Description

      Valgrind memcheck shows not one-time, but repeated "definitely lost" memory leaks in QML Loader:

      1. Image with ShaderEffect applied: 

      shader_leak_test.zip- sample app src, reloads Image with ShaderEffect each 100ms
      shader_memcheck_01_definite_only_38_iter.log- valgrind output
      shader_memcheck_02_definite_only_78_iter.xml- valgrind output for convenient import in QtCreator

      ==460027== 1,904 bytes in 34 blocks are definitely lost in loss record 53,819 of 54,478
      ==460027==    at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==460027==    by 0x11BEC702: QQuickOpenGLShaderEffectCommon::lookThroughShaderCode(QQuickItem*, QMetaObject const*, QQuickOpenGLShaderEffectMaterialKey::ShaderType, QByteArray const&) (qquickopenglshadereffect.cpp:371)
      ...
      
      ==460027== LEAK SUMMARY:
      ==460027==    definitely lost: 2,184 bytes in 45 blocks
      

      2. Colored Rectangle

      item_leak_test.zip- sample app src, reloads Rectangle each 50ms

      valgrind output
      item_memcheck_07_rect_200ms_1000_reloads.log
      item_memcheck_09_rect_50ms_500_trim_clear_no_result.log

      ==492485== 3,944 bytes in 493 blocks are definitely lost in loss record 20,699 of 21,013
      ==492485==    at 0x484A2F3: operator new[](unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==492485==    by 0x55CF8CA: QQmlContextData::initFromTypeCompilationUnit(QQmlRefPointer<QV4::ExecutableCompilationUnit> const&, int) (qqmlcontext.cpp:872)
      ...
      
      ==492485== LEAK SUMMARY:
      ==492485==    definitely lost: 4,032 bytes in 504 blocks
      

      NOTE: Calling trimComponentCache() and clearComponentCache() in sample #2 has no effect.

      Defect is similar to QTBUG-61536

       

      Our product Qt app has way more complex app scene and above leaks lead to a memory shortage in the system under a long run and rapid QML view switching by user.

      Below are examples of valgrind output for our product Qt app ran on the Linux desktop for a couple of minutes under the stress test for Loader:

      1. QQuickOpenGLShaderEffectCommon::lookThroughShaderCode()

      ==376054== 22,848 bytes in 408 blocks are definitely lost in loss record 102,877 of 103,679
      ==376054==    at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==376054==    by 0x5356702: QQuickOpenGLShaderEffectCommon::lookThroughShaderCode(QQuickItem*, QMetaObject const*, QQuickOpenGLShaderEffectMaterialKey::ShaderType, QByteArray const&) (qquickopenglshadereffect.cpp:371)
      ...
      

      2. QQmlContextData::initFromTypeCompilationUnit()

      ==376054== 3,776 bytes in 472 blocks are definitely lost in loss record 99,847 of 103,679
      ==376054==    at 0x484A2F3: operator new[](unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==376054==    by 0x6BCF8CA: QQmlContextData::initFromTypeCompilationUnit(QQmlRefPointer<QV4::ExecutableCompilationUnit> const&, int) (qqmlcontext.cpp:872)
      ...
      

       3. QQmlPropertyCache::copyAndReserve()

      ==376054== 344 bytes in 43 blocks are definitely lost in loss record 82,018 of 103,679
      ==376054==    at 0x484A2F3: operator new[](unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==376054==    by 0x6C047D7: QLinkedStringHash<QPair<int, QQmlPropertyData*> >::linkAndReserve(QLinkedStringHash<QPair<int, QQmlPropertyData*> > const&, int) (qlinkedstringhash_p.h:82)
      ==376054==    by 0x6BFF875: copy (qqmlpropertycache.cpp:265)
      ==376054==    by 0x6BFF875: QQmlPropertyCache::copyAndReserve(int, int, int, int) (qqmlpropertycache.cpp:281)
      ...
      

      Attachments

        For Gerrit Dashboard: QTBUG-119301
        # Subject Branch Project Status CR V

        Activity

          People

            lagocs Laszlo Agocs
            evnovikov Evgenii Novikov
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change