Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Memory leak in QPropertyAnimation



  • Hello,

    could you please help my with investivation. Why this part of code cased to a memory leak?

    @
    QPropertyAnimation *animation = new QPropertyAnimation(ui->createAdv, "geometry");
    animation->setDuration(1100);
    animation->setStartValue(QRect(0, -20, 60, 31));
    animation->setEndValue(QRect(0, 82, 200, 31));
    connect(animation,SIGNAL(finished()),animation,SLOT(deleteLater()));
    animation->start();@


  • Moderators

    looks good so far IMHO, as long as there are no console warnings and connect() returns true.

    btw. you can also do this to safe the connection of signals at all:
    @
    animation->start(QAbstractAnimation::DeleteWhenStopped);
    @



  • Hi,

    thanks, I'll try with DeleteWhenStopped.


  • Moderators

    why do you know there is a memory leak in first place?



  • I checked my application with Valgrind on Linux and it shows memory leaks. Also leaks observed by WindowsTaskManager while I run animation.


Log in to reply