Important: Please read the Qt Code of Conduct -

OSX - memory allocation - Free vs Inactive memory

  • I have an application that creates loads of objects and releases them again fairly quickly.

    All of this memory seems to end up in OSX's "inactive memory" pool while new allocations are being eaten from the "free memory" pool.

    According to apple this is normal and inactive memory is supposed to be reclaimed as free. ( )

    This however doesn't seem to be happening and though my application never uses more then say 50MB of real memory, it eats through GB's of memory on the way that ends up as inactive. When OS reaches some low free number ( say 50MB free memory ) it starts paging and everything slows to a crawl. My application is still not using more then 50 MB...

    This is clearly an OSX issue ( at least it seems that way ), but is there any way i could allocate more smartly. For instance start by allocating a large region and then just use that memory? Would i have to write a custom malloc implementation to stick between Qt and OSX?

    Any ideas?

  • It seems i was a bit quick about jumping to memory allocations causing this.

    I'm reading lots of files from the disk. This memory ( i presume disk cache ) doesn't get freed but rather stays as inactive.

    Any way to force OSX to free the cached memory used when reading files?

  • @
    #include "fcntl.h"

    QFile f(path);

    Seems to do it!

Log in to reply