I've seen other questions up on here before relating to this, but my issue doesn't revolve around a QVector containing pointers.
I have a 'Mesh' class which contains several QVector< T >'s , for holding vertices, indices, normals, etc, all held as standard objects.
As of recently I've noticed that each time I delete a mesh, the amount of memory used by my application doesn't decrease. I've been monitoring my applications memory usage with the Windows Task Manager, and have seen it go as high as 1000mb without dropping a single byte.
I have verified with a debugger that I am reaching the deconstructor of my mesh class, and my vectors are being deleted, but the memory still isn't being freed.
The deconstructor in question:
Mesh::~Mesh()
{
QVector<QVector3D> *vertices = this->vertices;
QVector<QVector3D> *normals = this->normals;
QVector<QVector3D> *tangents = this->tangents;
QVector<QVector2D> *textures = this->UVMap;
QVector<GLushort> *indices = this->indices;
vertices->clear();
vertices->squeeze();
delete vertices;
normals->clear();
normals->squeeze();
delete normals;
tangents->clear();
tangents->squeeze();
delete tangents;
textures->clear();
textures->squeeze();
delete textures;
indices->clear();
indices->squeeze();
delete indices;
}
I have used the Visual Leak Detector, and it seems to mostly show leaks within the library I'm using (Qt), in addition to telling me that some of my constructors are leaking, like the following:
Mesh::Mesh()
{
vertices = new QVector<QVector3D>();
indices = new QVector<GLushort>();
UVMap = new QVector<QVector2D>();
normals = new QVector<QVector3D>();
tangents = new QVector<QVector3D>();
}
But I don't see any problems here, since those objects were not initialized prior to those calls.
I really don't know much about smart pointers yet, but I'm hesitant to switch over everything in my application to use them because I don't know if they would even help really or perfectly replace my current usage without any issues. For instance I may pass some pointers around (like an entire mesh for instance) to another class, but I may not want that other class to delete that mesh upon its own destruction.
Edit: I thought I had a decently written out question but it seems people prefer to bandwagon downvotes instead. I will try other programs to monitor my problem.
There is not at all any memory leak. Following is the output given by
valgrind
If you really want to check for memory leak, you should use specialist software such as
valgrind
(for linux).valgrind
is the an excellent tool for this purpose.