Memoy leak using QtCharts
-
@Christian-Ehrlicher Thank you. It's the first time I see *new in c++ what does it mean?
-
@Christian-Ehrlicher Thank you. It's the first time I see *new in c++ what does it mean?
@aawawa
Hi
Its a Dereference
http://www.cplusplus.com/doc/tutorial/pointers/
See section Dereference operator (*) -
@mrjj yes... I understand... But I don't understand the location of the asterix (*). I am used for example to write
int *a = new int;
what does
*new int
means?
-
Ok, no memleak at all. You testcase is wrong / inaccurate.
The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all. -
@Christian-Ehrlicher said in Memoy leak using QtCharts:
Ok, no memleak at all. You testcase is wrong / inaccurate.
The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.It seems to me that there are some memory leaks happening here.
This code increases memory usage continuously:
aSeries->remove(aSeries->points().size() - 1);
aSeries->append(timestamp, mean);
Bit this one does not:
aSeries->replace(aSeries->points().size() - 1, timestamp, mean);
I'm using Qt 5.11.2.
-
@Christian-Ehrlicher said in Memoy leak using QtCharts:
Ok, no memleak at all. You testcase is wrong / inaccurate.
The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.It seems to me that there are some memory leaks happening here.
This code increases memory usage continuously:
aSeries->remove(aSeries->points().size() - 1);
aSeries->append(timestamp, mean);
Bit this one does not:
aSeries->replace(aSeries->points().size() - 1, timestamp, mean);
I'm using Qt 5.11.2.
@JosuGZ
In the last post 4 months ago made by @Christian-Ehrlicher, he explained that memory would only be recovered (and hence [hopefully] not permanently grow) when the OP allowed his code to reach the main event loop. I don't know howreplace
works, butremove
surely will do a deferred delete. So in your example you need to be clear/show us how your code hits the event loop each time after do theremove
/append
? -
@Christian-Ehrlicher said in Memoy leak using QtCharts:
Ok, no memleak at all. You testcase is wrong / inaccurate.
The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.It seems to me that there are some memory leaks happening here.
This code increases memory usage continuously:
aSeries->remove(aSeries->points().size() - 1);
aSeries->append(timestamp, mean);
Bit this one does not:
aSeries->replace(aSeries->points().size() - 1, timestamp, mean);
I'm using Qt 5.11.2.
hi @JosuGZ and welcome
if you only monitor the memory your OS gives your application, then that is inaccurate.
You have no influence over when the os decides that your freed memory will no longer be reserved for your application.
Therefore
remove -> append is memory is "freed" and a new allocation happens
replace -> new data overwrites old data -
hi @JosuGZ and welcome
if you only monitor the memory your OS gives your application, then that is inaccurate.
You have no influence over when the os decides that your freed memory will no longer be reserved for your application.
Therefore
remove -> append is memory is "freed" and a new allocation happens
replace -> new data overwrites old data@J.Hilk said in Memoy leak using QtCharts:
hi @JosuGZ and welcome
if you only monitor the memory your OS gives your application, then that is inaccurate.
You have no influence over when the os decides that your freed memory will no longer be reserved for your application.
Therefore
remove -> append is memory is "freed" and a new allocation happens
replace -> new data overwrites old dataAn order of magnitude more RAM needed for a simple app is not an OS problem.
Two tests more replacing the offending line, one with small allocations:
char *test = (char *)malloc(10); test[5] = 't'; // Touching memory aSeries->replace(aSeries->points().size() - 1, ms, mean); free(test);
Another with bigger allocations:
char *test = (char *)malloc(10000); test[5000] = 't'; // Touching memory aSeries->replace(aSeries->points().size() - 1, ms, mean); free(test);
Both keep memory usage low as expected.
Even this keeps the memory constant:
QWidget *test = new QWidget; aSeries->replace(aSeries->points().size() - 1, ms, mean); test->deleteLater();
Something is happening with this library and I'm not the only one with issues.