Memory Leak when sending images
pauloloid opened this issue · 4 comments
Hello,
I use the
NZMQT_INLINE bool ZMQSocket::sendMessage(const QByteArray& bytes_, SendFlags flags_)
function for sending a QByteArray of an QImage.
So I call
socket_->sendMessage(getImageCapture());
where getImageCapture() is:
QByteArray Example::getImageCapture()
{
/* newimage holds an pointer to the image */
QBuffer buffer;
if(!newImage)
return NULL;
newImage->save(&buffer, "PNG");
delete newImage;
return buffer.buffer();
}
Everytime the memory increases. After a certain time I get a stackoverflow.
How can I handle this?
sendMessage
uses QByteArray
. Try to use getImageCapture().buffer()
If the problem still persists this could mean that there actually is a memory leak in nzmqt. I have heard similar problems from a user. However, I rarely send huge amounts of data so the error may cumulate not as fast as for you.
Hello,
I am sorry, I just recognized, it does not have something to do with ZeroMQ or nzmqt.
The way I got my QImage (by signal and slot) was designed wrong.
Anyway, thank you for your fast response!
Yes, implementation looks correct. zmq frees the message_t
automatically. However, you may consider constructing your own ZMQMessage
objects in order to minimize overhead.