0

I want to add an OpenGLWidget to a layout and when my job is done, I want to clean up everything about OpenGLWidget, but When I was open the widget and close with Qt::WA_DeleteOnClose attribute, the memory is not freeing up completely. Is that normal or am I not know the right usage. I was read the documentation (https://doc.qt.io/qt-5/qopenglwidget.html) and try everything but I can't remove that 40 mb allocation from the memory when creating the widget and closing after them. It is just delete 3-4 mb after close and delete operation. I will use this for another project. (I have to open OpenGLWidget, show some triangles and close the Widget.)

I was try to use makeCurrent() and doneCurrent(), deleteLater() and some more operations but it is not work.

#include "MainWindow.h"
#include "ui_MainWindow.h"
#include<QOpenGLWidget>

QOpenGLWidget *openglWidget;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    openglWidget = new QOpenGLWidget;
    openglWidget->setAttribute(Qt::WA_DeleteOnClose);
    ui->gridLayout->addWidget(openglWidget);
}

void MainWindow::on_pushButton_2_clicked()
{
    ui->gridLayout->removeWidget(openglWidget);
    openglWidget->close();
    delete openglWidget;
}
  • Can you explain why you think `"the memory is not freeing up completely"`? Are you using valgrind or some other memory checker? – G.M. Aug 17 '20 at 12:00
  • I observed on Task Manager, also I installed valgrind but didn't used. – Hüseyin Babuc Aug 17 '20 at 12:06
  • Task Manager is not useful for this kind of analysis. When an application frees memory (delete, free etc.) it is really just telling the runtime that the memory is no longer needed by the application. There is no guarantee that the runtime will hand the memory in question back to the OS and, hence, no reason for the deallocation to show up in Task Manager. Try using valgrind instead. – G.M. Aug 17 '20 at 12:10
  • I know that using valgrind gives me more precise informations, but I also want to learn that I can create and delete some other thing and saw the memory decreasing and increasing from Task manager, but why OpenGL windows is not removing like that, is this a normal circumstance or I am not freeing up OpenGL window properly. I want to learn this. – Hüseyin Babuc Aug 17 '20 at 13:05

0 Answers0