[Solved]Why delete QStandardItemModel doesn't cause a memory decrease?
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.
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.
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
KNMusicPlaylistListItem() : QStandardItem()
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:
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]