1,284 (20 direct, 1,264 indirect) bytes in 1 blocks are definitely lost in loss record
m_FooThreadPtr = QSharedPointer<FooThread>(new FooThread);
m_FooThreadPtr = QSharedPointer<FooThread>(new FooThread, &QObject::deleteLater);
==3164== 894 (20 direct, 874 indirect) bytes in 1 blocks are definitely lost in loss record 241 of 267==3164== at 0x4023F02: operator new(unsigned int) (vg_replace_malloc.c:214)==3164== by 0x8058A62: FooThread:: FooThread () (FooThread.cpp:27)==3164== by 0x8061EEE: FooDialog:: FooDialog (QWidget*) (FooDialog.cpp:11)==3164== by 0x804FD0D: MainWindow::slotRemove() (MainWindow.cpp:315)==3164== by 0x8063F5F: MainWindow::qt_metacall(QMetaObject::Call, int, void**) (moc_MainWindow.cpp:95)==3164== by 0x4D28142: QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) (qmetaobject.cpp:237)==3164== by 0x4D385A3: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (qobject.cpp:3272)==3164== by 0x491F958: QAbstractButton::clicked(bool) (moc_qabstractbutton.cpp:206)==3164== by 0x45E6678: QAbstractButtonPrivate::emitClicked() (qabstractbutton.cpp:546)==3164== by 0x45E7E7F: QAbstractButtonPrivate::click() (qabstractbutton.cpp:539)==3164== by 0x45E80FB: QAbstractButton::mouseReleaseEvent(QMouseEvent*) (qabstractbutton.cpp:1121)==3164== by 0x41EE8B8: QWidget::event(QEvent*) (qwidget.cpp:8187)
QObject: shared QObject was deleted directly. The program is malformed and may crash.
==3164== 4,048 bytes in 22 blocks are possibly lost in loss record 262 of 267==3164== at 0x4022A92: memalign (vg_replace_malloc.c:532)==3164== by 0x4022AE2: posix_memalign (vg_replace_malloc.c:660)==3164== by 0x51605D3: ??? (in /usr/lib/libglib-2.0.so.0.1600.6)==3164== by 0x51617E0: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.1600.6)==3164== by 0x5137BEC: ??? (in /usr/lib/libglib-2.0.so.0.1600.6)==3164== by 0x5175D94: g_get_language_names (in /usr/lib/libglib-2.0.so.0.1600.6)==3164== by 0x5104476: g_thread_init (in /usr/lib/libgthread-2.0.so.0.1600.6)==3164== by 0x4D52A09: QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(_GMainContext*) (qeventdispatcher_glib.cpp:299)==3164== by 0x424809C: QGuiEventDispatcherGlibPrivate::QGuiEventDispatcherGlibPrivate() (qguieventdispatcher_glib.cpp:171)==3164== by 0x4248182: QGuiEventDispatcherGlib::QGuiEventDispatcherGlib(QObject*) (qguieventdispatcher_glib.cpp:186)==3164== by 0x420E07F: QApplicationPrivate::createEventDispatcher() (qapplication_x11.cpp:605)==3164== by 0x4D25FF8: QCoreApplication::init() (qcoreapplication.cpp:552)
C++ (Qt)struct Thread : public QThread{ ... Thread (QObject *parent) { connect (this, SIGNAL (finished ()), parent, SLOT (thread_dead ())); }}; struct Main : public QFrame{public slots: void thread_dead () const { delete (Thread*) QObject::sender (); }...
class Worker : public QObject{ Q_OBJECTpublic:Worker(QVector<QString> &vector)m_vector:(vector){}public slots: void work();signals: void finished();private:QVector<QString> m_vector};void Worker::work(){ // do some work emit finished();}int main(){ QThread thread;QVector<QString> vector;…add data to vector Worker w(vector); w.moveToThread(&thread); QObject::connect(&thread, SIGNAL(started()), &w, SLOT(work())); QObject::connect(&w, SIGNAL(finished()), &thread, SLOT(quit())); thread.start();}
...void thread_dead () const{ (Thread*) QObject::sender ()->wait(); delete (Thread*) QObject::sender ();}...