Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Memory leak in QtConcurrent::run() ?
Forum Updated to NodeBB v4.3 + New Features

Memory leak in QtConcurrent::run() ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 578 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HowP
    wrote on last edited by HowP
    #1

    Hello,

    I am experiencing some unpleasant problem with QtConcurrent::run(). Sometimes it has possibly lost bytes sometimes it does not. Can someone explain me what is happening here? Thank you. QT Version - qt5-base 5.13.0, GCC version - 9.1.0, Arch Linux

    Code here:

    #include <qfuture.h>
    #include <QtConcurrent/QtConcurrent>
    
    QFuture<int> AsyncFunction()
    {
        auto task = QtConcurrent::run([]()
            {
                return 5;
            });
    
        return task;
    }
    
    void testAsyncException()
    {
        auto task = AsyncFunction();
        task.waitForFinished();
    }
    
    int main ()
    {
        testAsyncException();
    }
    

    Valgrind output: "valgrind --leak-check=full ./Sandbox" - Grep Error Summary for 10 runs

    ==13333== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    ==13336== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    ==13345== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    ==13354== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    ==13363== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    ==13372== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
    ==13381== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
    ==13391== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    ==13400== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
    ==13406== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
    

    Valgrind output for the error:

    ==14117== Memcheck, a memory error detector
    ==14117== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==14117== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
    ==14117== Command: ./Sandbox
    ==14117== 
    ==14117== 
    ==14117== HEAP SUMMARY:
    ==14117==     in use at exit: 19,884 bytes in 23 blocks
    ==14117==   total heap usage: 79 allocs, 56 frees, 98,073 bytes allocated
    ==14117== 
    ==14117== 320 bytes in 1 blocks are possibly lost in loss record 21 of 23
    ==14117==    at 0x483AB65: calloc (vg_replace_malloc.c:752)
    ==14117==    by 0x4012AC1: allocate_dtv (in /usr/lib/ld-2.29.so)
    ==14117==    by 0x4013431: _dl_allocate_tls (in /usr/lib/ld-2.29.so)
    ==14117==    by 0x4D991AD: pthread_create@@GLIBC_2.2.5 (in /usr/lib/libpthread-2.29.so)
    ==14117==    by 0x4946F9B: QThread::start(QThread::Priority) (in /usr/lib/libQt5Core.so.5.13.0)
    ==14117==    by 0x4949E44: QThreadPoolPrivate::startThread(QRunnable*) (in /usr/lib/libQt5Core.so.5.13.0)
    ==14117==    by 0x494AEEB: QThreadPoolPrivate::tryStart(QRunnable*) (in /usr/lib/libQt5Core.so.5.13.0)
    ==14117==    by 0x494B5E9: QThreadPool::start(QRunnable*, int) (in /usr/lib/libQt5Core.so.5.13.0)
    ==14117==    by 0x10AEE2: QtConcurrent::RunFunctionTaskBase<int>::start(QThreadPool*) (qtconcurrentrunbase.h:87)
    ==14117==    by 0x10AC75: QtConcurrent::RunFunctionTaskBase<int>::start() (qtconcurrentrunbase.h:78)
    ==14117==    by 0x10A493: std::enable_if<!QtPrivate::HasResultType<AsyncFunction()::{lambda()#1}>::Value, QFuture<decltype ({parm#1}())> >::type QtConcurrent::run<AsyncFunction()::{lambda()#1}>(QtPrivate::HasResultType) (qtconcurrentrun.h:108)
    ==14117==    by 0x10A3AF: AsyncFunction() (main.cpp:9)
    ==14117== 
    ==14117== LEAK SUMMARY:
    ==14117==    definitely lost: 0 bytes in 0 blocks
    ==14117==    indirectly lost: 0 bytes in 0 blocks
    ==14117==      possibly lost: 320 bytes in 1 blocks
    ==14117==    still reachable: 19,564 bytes in 22 blocks
    ==14117==         suppressed: 0 bytes in 0 blocks
    ==14117== Reachable blocks (those to which a pointer was found) are not shown.
    ==14117== To see them, rerun with: --leak-check=full --show-leak-kinds=all
    ==14117== 
    ==14117== For counts of detected and suppressed errors, rerun with: -v
    ==14117== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This is no memleak in a way you should worry about, it's one block which is needed to handle the different threads afaiu. It's created once and not deleted because there may be other threads created afterwards.
      And even if you define it as memleak it's not Qt's fault since pthread is not Qt. And searching for dl_allocate_tls will show you that others also stumbled upon this.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • H Offline
        H Offline
        HowP
        wrote on last edited by
        #3

        Awesome, thank you.. I was not sure because the possibly lost block was not reported by valgrind on each run.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved