Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Memory Usage after object.destroy


  • Qt Champions 2017

    Hi

    I created object dynamically in QML. When object is created memory usage increases. When I object is deleted using object.destroy, I don't see memory usage is getting decreased.

    1. Memory usage remains the same as before delete. Any idea why ?

    Tried this on MAC with Qt 5.5. and 5.7. Same result.



  • Hi ,

    Im also facing similar issue.
    Any update is there on this topic?

    Regards
    Mowlee



  • @Mowlee , @dheerendra
    How are you two measuring the "memory usage" here?

    If you are using some tool which shows the overall memory usage of your process, be aware that it is extremely likely that freed memory from an application will remain in its memory allocation awaiting re-use in future allocations. For example, if it ultimately uses something like malloc() to get its memory that maintains its own table of blocks in use & blocks no longer used but available for re-use. To "hand memory back to the OS" requires calling something like brk(), and that only works if the memory to be returned is at the top of the allocated area; I would doubt Qt will call this.

    So if you really want to know how much memory is actually in use/free for reallocation you will need to use a dedicated tool to walk the heap/handles within the process, not just ps or taskman.



  • @JonB
    Thank you for reply.

    I didnt use any tool for memory usage. But my issue looks similar to @dheerendra 's issue.

    1. I have created a object.
    2. At this time children length of object is 1 [object.parent.children.length]
    3. Destroyed that and created another object.
    4. At this point, the children length of the object is 2[object.parent.children.length]

    After destroying the object(object.destroy()), do we need to use any other call to clear memory?

    Regards
    Mowlee


  • Moderators

    @Mowlee you can call gc() to force the garbage collector to run, if it helps.



  • @J-Hilk

    After object.destroy(), called gc(). I am seeing still the issue is not resolved.

    Regards
    Mowlee


Log in to reply