# Memory leak in QVTK widget and PCL visualizer

**URL:** https://discourse.vtk.org/t/memory-leak-in-qvtk-widget-and-pcl-visualizer/6881
**Category:** Development
**Created:** [October 14, 2021, 3:33am UTC](https://discourse.vtk.org/t/memory-leak-in-qvtk-widget-and-pcl-visualizer/6881 "2021-10-14T03:33:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SurajJadhav](https://discourse.vtk.org/user_avatar/discourse.vtk.org/surajjadhav/32/3874_2.png) [@SurajJadhav](https://discourse.vtk.org/u/SurajJadhav)
#### Post date: [October 14, 2021, 3:33am UTC](https://discourse.vtk.org/t/memory-leak-in-qvtk-widget-and-pcl-visualizer/6881/1 "2021-10-14T03:33:14Z")

</div>

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:

```auto
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:

```auto
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 the constructor is giving lot of memory leak issues. How to destruct the qvtkwidget properly?

---

<div class="post-metadata">

### Author: ![jcfr](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jcfr/32/466_2.png) [@jcfr](https://discourse.vtk.org/u/jcfr)
#### Post date: [October 14, 2021, 4:32am UTC](https://discourse.vtk.org/t/memory-leak-in-qvtk-widget-and-pcl-visualizer/6881/2 "2021-10-14T04:32:16Z")

</div>

Thanks for reporting the problem.

What do you exactly mean by “memory leaks” ? Are you referring to issues discovered using tool like `memcheck`, or are these reported as [vtkDebugLeaks](https://vtk.org/doc/nightly/html/classvtkDebugLeaks.html) ?

To better understand how the different objects are created, could you share a like to a minimal GitHub project allowing to reproduce the problem ? The project would include relevant source files, a `CMakeLists.txt`, a `README.md` detailing how to download and build the dependencies (VTK, pcl, …)

Looking at the snippet you shared, it is unclear how the `Ui::SiLS` object is implemented.

---

<div class="post-metadata">

### Author: ![SurajJadhav](https://discourse.vtk.org/user_avatar/discourse.vtk.org/surajjadhav/32/3874_2.png) [@SurajJadhav](https://discourse.vtk.org/u/SurajJadhav)
#### Post date: [October 14, 2021, 4:52am UTC](https://discourse.vtk.org/t/memory-leak-in-qvtk-widget-and-pcl-visualizer/6881/3 "2021-10-14T04:52:03Z")

</div>

Memory leak issues were generated by valgrind which is present in Qt Creator. I have committed the project files to Github [here](https://github.com/Surajj4837-th/SiLS). Readme file shows detailed installation setup.

---

<div class="post-metadata">

### Author: ![SurajJadhav](https://discourse.vtk.org/user_avatar/discourse.vtk.org/surajjadhav/32/3874_2.png) [@SurajJadhav](https://discourse.vtk.org/u/SurajJadhav)
#### Post date: [October 18, 2021, 10:17am UTC](https://discourse.vtk.org/t/memory-leak-in-qvtk-widget-and-pcl-visualizer/6881/4 "2021-10-18T10:17:16Z")

</div>

One of the issue trace back is as shown below:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/10c8878d9d346416a0d60352b246b1b510eb0c76.png)  
How to debug in these lib files?
