Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFileDialog memory leak?

I'm just writing a small app in which I have function which looks like:

QString askForDir()
{
    return QFileDialog::getExistingDirectory(this, "Choose directory", QString(""));
}

Since I've added this function I've mentioned that memory allocation became pretty strange after using this function ( askForDir() ).
I use OS X Instruments app for debugging needs so here's what I've got:
Snapshot Peaks are the moments when askForDir() function works, I mean building dir-tree.
Between these peaks there are spaces where nothing happened, I mean app doing nothing, just waiting for other action from user.
As you can see memory allocation is growing. If you want numbers:

at 30sec - 91 Mb
at 50sec - 113 Mb
at 1m15sec - 135 Mb


Each time it grows at 22 Mb

I've tried to explore it and changed askForDir() function to smth like this:

QString askForDir()
{
    return "/Users/username/Desktop";
}

All I was speaking above disappeared. So, I concluded that the problem is in QFileDialog.


Here's what I'm using:

  • OS X 10.9.4
  • Xcode 5.1.1, Carbon
  • Qt 4.8.6

Has anyone else the same "problem"?

like image 839
tema Avatar asked Jul 01 '14 14:07

tema


1 Answers

It seems, that I figure it out.
This is not a leak, neither a bug. If you open the notepad on windows xp, the memory usage is 4mb. Click on file->open and then the memory usage grows up to 9mb. Close the dialog and you can see the memory usage is not decreasing (or just a little around 8.9Mb). Windows is obviously caching/creating stuff on our back (caching for example). -> This is for the native usage.


For the non-native, It's the same. The first time you open a QFileDialog Qt library caches some icons for a later usage. This is at application level. This make navigation in the filedialog, as well as later on if you open the dialog again much faster. It's not a leak, when the app is closed everything is released.


Looks like the same thing happening everywhere, so, I think, the question is out of interest now.

like image 113
tema Avatar answered Sep 27 '22 18:09

tema