简体   繁体   中英

QVector memory leak?

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

==7881== Memcheck, a memory error detector
==7881== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7881== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==7881== Command: ./abstractitemmodel
==7881== 
==7881== 
==7881== HEAP SUMMARY:
==7881==     in use at exit: 0 bytes in 0 blocks
==7881==   total heap usage: 8 allocs, 8 frees, 168 bytes allocated
==7881== 
==7881== All heap blocks were freed -- no leaks are possible
==7881== 
==7881== For counts of detected and suppressed errors, rerun with: -v
==7881== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM