Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Why delete QStandardItemModel doesn't cause a memory decrease?

[Solved]Why delete QStandardItemModel doesn't cause a memory decrease?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saki
    wrote on last edited by
    #1

    I find out an odd thing: I delete a QStandardItemModel in a destructor, and it really did(I wrote a qDebug in the destructor to check if it runs). But I check the memory usage in task manager, I find out that there's no change of the memory usage. And when I instantiate another QStandardItemModel, the memory goes up. It doesn't seem like using a memory pool in the QStandardItemModel.
    I've known in the documentation of ~QStandardItemModel(), it writes:
    Destructs the model. The model destroys all its items.
    But it can't! Did I use the QStandardItemModel in a wrong way? How can I recover those leaked memory? Or it doesn't leak?


    The task manager refresh the 'memory' column too slow. Wait for several seconds after delete a model, the memory usage decrease. There's nothing wrong. I'm so sorry.

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Do you allocate anything extra in your model or the items? If you keep creating and destroying the model (like a thousand times in a loop) does the memory usage go up or stops at some point? Can you share your code?

      What OS are you on? What Qt version and compiler? Have you tried any better tools than a task manager (It's a very poor tool for finding leaks) like Valgrind or VLC?

      When you ask a question share as many details as you can think of or it's a guessing game for anyone who wants to help.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Saki
        wrote on last edited by
        #3

        Sure, I'm still a fresher to Qt. I'm so sorry for forgetting these things.
        I do allocate two QObject in the model, But I rewrite the destructor to delete it.
        I didn't keep creating and destorying the model. I'm making a playlist using QStandardItemModel. Here's a sample code:

        @
        class KNMusicPlaylistListItem : class QStandardItem
        {
        public:
        KNMusicPlaylistListItem() : QStandardItem()
        {
        m_playlistModel=new QStandardItemModel();
        }
        ~KNMusicPlaylistListItem()
        {
        delete m_playlistModel;
        }
        private:
        QStandardItemModel *m_playlistModel;
        }
        @

        This is the special item I'm used. And I create another QStandardItemModel to storage these items. When I create a KNMusicPlaylistListItem, it will create a QStandardItemModel, and when I delete one KNMusicPlaylistListItem it should delete the m_playlistModel. But I find that the memory in task manager doesn't change.
        I do this test on Windows 7 Ultimate x64 with official Qt 5.3.2 MinGW offline version(I didn't change the compiler). I'm so sorry that I'm still not using any other tools to check this problem. But I mentioned that the memory increase is proportional to the rows and never decrease. When I generate new model the memory increase again.
        It's hard for me to paste all the code here. My project is hosted on Github:
        https://github.com/Kreogist/Mu/tree/new-core
        The code is in the new-core branch. (To compile this project you need to get un4seen's bass library) In file Mu / src / plugin / module / knmusicplugin / plugin / knmusicplaylistmanager / knmusicplaylist / sdk / knmusicplaylistlistitem.cpp

        [edit: added missing coding tags @ SGaist]

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved