QByteArray possible memory Leak ?
-
Hi ,
Whane I trace the memory leak the Mac Instruments app point me below code :
mq_dataLoad *dl = new mq_dataLoad; //QVariant . includes image and text/// QImage image = qpix.toImage(); QByteArray ba_catch; QBuffer buffer_catch(&ba_catch); buffer_catch.open(QIODevice::WriteOnly); image.save(&buffer_catch, "PNG"); dl->image = ba_catch; dl->text = MqttUserName + ":" + QString::number(mq_chip_code) ; mq_chip_code++; QByteArray byteArray_; QDataStream stream(&byteArray_ , QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_10); free(dl);Do you have any idea why this is leaking memory ?
-
There is no byte array anywhere. It's a false positive of your tool. Also you tool should tell exactly where the leak should be.
-
Hi
Just a note.
free(dl);
should that not be
delete dl;
since you are creating it with new ? -
Hi ,
Whane I trace the memory leak the Mac Instruments app point me below code :
mq_dataLoad *dl = new mq_dataLoad; //QVariant . includes image and text/// QImage image = qpix.toImage(); QByteArray ba_catch; QBuffer buffer_catch(&ba_catch); buffer_catch.open(QIODevice::WriteOnly); image.save(&buffer_catch, "PNG"); dl->image = ba_catch; dl->text = MqttUserName + ":" + QString::number(mq_chip_code) ; mq_chip_code++; QByteArray byteArray_; QDataStream stream(&byteArray_ , QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_10); free(dl);Do you have any idea why this is leaking memory ?
mq_dataLoad *dl = new mq_dataLoad; //QVariant . includes image and text///
free(dl);As @mrjj has observed, this is wrong.
freewill not callQVariant'sdestructor, and at a guess that will be enough for a memory leak. Since you have previously gonedl->image = ba_catch;, that's aQByteArray, so it's probably where the leak is. -
There is no byte array anywhere. It's a false positive of your tool. Also you tool should tell exactly where the leak should be.
what is the suggested memory leak detection tool ? valgrind keep very slow by the way.
@JonB its struct :
struct mq_dataLoad { QString text; QByteArray image; }; -
what is the suggested memory leak detection tool ? valgrind keep very slow by the way.
@JonB its struct :
struct mq_dataLoad { QString text; QByteArray image; };@RahibeMeryem
I don't see how it's such astructgiven that the comment against it saysQVariant, but there you are....Yes
valgrindwill be "slow". Before you worry about anything else, have you or have you not tried replacing yourfree(dl)withdelete dl? -
Lets try to delete and let you know...
-
@JonB delete looks worked in Mac . It shows zero leak.. very good news.
What is interesting that same code looks leaking in ubuntu 18.04 ! How is that possible ?
Is there any tools like "Instruments app mac os x " in Linux OS ?
valgrind crashing when the thread started in app, still trying but ...