openGl: m_customPlot->setOpenGl(true);
Other memory leaks have been ruled out
openGl: m_customPlot->setOpenGl(true);
Other memory leaks have been ruled out
I found that the memory was leaking when the mouse dragged chart and scroll zoomed, which was probably caused by painter redrawing
It does have something to do with the m_customplot->report() with the drawing, I set 1 once a second,Memory leaks are slowing down
I'm locating it now this function
void QCPLayer::draw(QCPPainter *painter) { foreach (QCPLayerable *child, mChildren) { if (child->realVisibility()) { painter->save(); painter->setClipRect(child->clipRect().translated(0, -1)); child->applyDefaultAntialiasingHint(painter); child->draw(painter); painter->restore(); } } }
But don't see what's causing it
Hi
I found a method yesterday, inspired by the that turning off openGl will immediately release the memory that has been leaked, and then I'll define a timer to look at the process memory every second, if to a certain memory setOpenGl(false) and then setOpenGl(true).
be confined to Windows
void MyClass::checkMemoryUsage()
{
//Gets the current process handle
HANDLE hProcess = GetCurrentProcess();
//Gets the process memory information structure
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
{
//Gets the amount of physical memory in bytes used by the current process
SIZE_T memoryUsed = pmc.WorkingSetSize;
//Convert bytes to GB
double memoryUsedGB = static_cast<double>(memoryUsed) / (1024 * 1024 * 1024);
//Check whether the memory usage is greater than 1GB
if (memoryUsedGB > 1.0)
{
qDebug() << " Memory usage is above 1GB.";
m_customPlot->setOpenGl(false);
m_customPlot->setOpenGl(true);
}
}
//Close the process handle
CloseHandle(hProcess);
}
I'll resend it
void ParentView::checkMemoryUsage() { // Gets the current process handle HANDLE hProcess = GetCurrentProcess(); // Gets the process memory information structure PROCESS_MEMORY_COUNTERS pmc; if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) { // Gets the amount of physical memory in bytes used by the current process SIZE_T memoryUsed = pmc.WorkingSetSize; // Convert bytes to GB double memoryUsedGB = static_cast<double>(memoryUsed) / (1024 * 1024 * 1024); // Check whether the memory usage is greater than 1GB if (memoryUsedGB > 1.0) { qDebug() << " Memory usage is above 1GB."; m_customPlot->setOpenGl(false); m_customPlot->setOpenGl(true); } } // Close the process handle CloseHandle(hProcess); }
Just comment out this sentence // draw(painter);
void QCPLayer::drawToPaintBuffer() { QSharedPointer<QCPAbstractPaintBuffer> pb = mPaintBuffer.toStrongRef(); if (pb) { if (QCPPainter *painter = pb->startPainting()) { if (painter->isActive()){ //内存泄漏 // draw(painter); } else{ qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; } delete painter; pb->donePainting(); } else qDebug() << Q_FUNC_INFO << "paint buffer returned nullptr painter"; } else qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; }
Hi
I don't know if I'm right: the rChildren container, The object in the container needs to be deleted if you are not using it, If you allocate memory in child->draw(), you need to free It when you're done.
official QCPLayerable->draw(QCPPainter* painter) introduce
(This function draws the layerable with the specified painter. It is only called byQCustomPlot, if the layerable is visible (setVisible).
Before this function is called, the painter's antialiasing state is set via applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was set to clipRect.)
I don't understand what you mean by that
you sent the function void QCPLayer::draw(QCPPainter *painter)
How do you turn on opengl, and what is the gpu usage rate after turning on, is it in qml or qwidget
When opengl is enabled in qml,gpu usage does not increase. Is qcustomplot not accelerated with opengl in qml