PDA

View Full Version : memory problem with curves in plots



lwz
5th December 2014, 08:35
We've deprived curve like this,


class BaseCurve : public QObject, public QwtPlotCurve
{
Q_OBJECT
LOG4QT_DECLARE_QCLASS_LOGGER
..........
~BaseCurve();
private:
..
QList<QwtPlotMarker *> m_markerList ;// some plot items in the curve.
..
}
BaseCurve::~BaseCurve() {
foreach (QwtPlotMarker *marker, foreach m_markerList}) {
delete marker;
}
}

Then we seem the BaseCurve as a plot item , when we close the plot, we first detach plot items which are inside the BaseCurve . We have checked very carefully to make sure every item created is deleted. But htop shows something's wrong, f.e, when we open the plot, memory consumption is 77 MB which would up to 135 MB after adding 100 BaseCurve into the plot. And it'll down to about 115 MB when closing the plot. Some memory taken by plot and basecurve are return to os, while some not.
We've used valgrind to check the code with no luck. Do you have some suggestion?

Uwe
5th December 2014, 10:11
Don't have a good link at hand, but malloc/free are no system calls ( maybe google for sbrk+malloc to understand how it works ).

Better do your test in a loop. When everything is o.k. you will see, that the value shown by htop won't grow with every loop as the memory freed from the previous loop will be reused.

Uwe

lwz
6th December 2014, 03:05
oh, I see.
what do you think of the way we deprive basecurve from QObject and QwtPlotCurve ? Is it ok ?
Do you think that we have all the items deleted this way?