0

I m using Ubuntu 20.04 with Qt5.12 for developing a QT project which uses a QVTK widget to display a 3D PCL visualiser. I m facing memory leak issues after defining the visualiser and vtk widget relationship. The header file contents are as follows:

class SiLS : public QMainWindow
{
    Q_OBJECT

public:

    SiLS(QWidget *parent = nullptr);
    ~SiLS();

private:

    Ui::SiLS *ui;
    pcl::visualization::PCLVisualizer::Ptr viewer_3D;
};

The cpp file contents are as follows:

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

    viewer_3D.reset (new pcl::visualization::PCLVisualizer ("viewer_3D", false));
    viewer_3D->setupInteractor (ui->qvtkWidget->GetInteractor (), ui->qvtkWidget->GetRenderWindow ());
    ui->qvtkWidget->SetRenderWindow(viewer_3D->getRenderWindow());
}

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

Only these 3 lines of code in constructor is giving lot of memory leak issues. Following screenshot shows few of the leaks identified by valgrind in Qt creator. enter image description here

SiLS.cpp:10:0 represents the following line in cpp file:

viewer_3D.reset (new pcl::visualization::PCLVisualizer ("viewer_3D", false));

surajj4837
  • 49
  • 1
  • 10
  • Is `SiLS` properly destroyed in the code that use it ? And why did you use reset() instead of the constructor initialization member to initialise `viewer_3D` ? Another reason could be that you copy `viewer_3D` somewhere in your code that will increment the internal shared_ptr ref counter, so when you destroy your `SiLS` instance, `viewer_3D` isn't destroyed with. – Bolo Oct 13 '21 at 14:46
  • As of now above given code is my complete code. I m actually trying to get help to write the destruction part for the QVTK and visualiser. I m not copying the object anywhere. – surajj4837 Oct 13 '21 at 16:58

0 Answers0