Report, QTextDocument (memory leak)
I have some issues with simple reports that my application makes by QTextDocument, html-page (template), QPrinter and QPrintPreviewDialog. I made classes for this stuff.
But recently I was realised that I have memory leak. so I tried to find where is it.
It seems that I found out smth but don't know exactly why this happening..
I threw out spec. classes and wrote just necessary code:
Code:
........
// in widget's constructor
........
// in widget'd destructor
delete document;
........
//----------------------------------------------------------------------------------------
void fmPartStatInRange::previewSelectionReport() {
QMessageBox::critical (this,
"", tr
("Error opening report file %1").
arg (file.
fileName ()));
return;
}
stream.
setCodec (QTextCodec::codecForName ("UTF-8"));
document->clear();
document->setHtml (stream.readAll ());
file.close ();
//----------------------------------------------------------------------------------------
void fmPartStatInRange
::print(QPrinter *printer
) { #ifdef QT_NO_PRINTER
Q_UNUSED(printer);
#else
document->print(printer);
#endif
}
//----------------------------------------------------------------------------------------
void fmPartStatInRange::printReport() {
#ifndef QT_NO_PRINTER
QPrintPreviewDialog preview(&printer, this);
preview.exec();
#endif
}
//----------------------------------------------------------------------------------------
void fmPartStatInRange::createReport() {
previewSelectionReport();
if (document)
printReport();
}
//----------------------------------------------------------------------------------------
I execute createReport() many times and see memory leak.
But if I comment this line:
Code:
document->setHtml (stream.readAll ());
that's all ok. no memory leak.
of course in this case I don't get any sence of report only white page.
I use 4.7.3 Qt ver.
unfortunately I haven't any opportunities to check out it on new Qt ver.
so what is wrong with this code or maybe it's a bug in Qt lib?
thanks in advance!
Re: Report, QTextDocument (memory leak)
How do you "see memory leak"?
2 Attachment(s)
Re: Report, QTextDocument (memory leak)
in win task manager for example.
here it is 24 Mb in memory before doing smth:
Attachment 7525
after 20 reports (35 Mb):
Attachment 7526
and it's keep growing if we do reports...
is it normal or I didn't catch smth?