Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to release memory from QByteArray and QByte Stream in QT

Tags:

c++

memory

qt

I want to know how can i relase QByteArray and QByteStream from QT specialy at this snippet code:

  QByteArray DicResourceByteArray;
  QDataStream out(&DicResourceByteArray, QIODevice::WriteOnly);

  QString encoded;
  out.writeRawData(DicBlock.data + pos, DicBlock.length - pos);


  encoded = QString(DicResourceByteArray.toBase64());
like image 355
Eagle Eye Avatar asked Aug 09 '11 11:08

Eagle Eye


1 Answers

All will be released automatically as soon as will run out of scope according to RAII concept. If you want to release memory explicitly, call something like clear() but that is unneeded - all cleaning will be done in QByteArray's destructor. With QDataStream situation is the same... Also note that this is strongly preferrable coding style - when you will create your own classes try to do the same. It saves a lot of headache with managing C-like pointers.

like image 67
Raiv Avatar answered Sep 18 '22 01:09

Raiv