[cfe-dev] libclang: Memory management

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 10 04:28:43 PST 2017


On 10 Mar 2017, at 12:19, Jusufadis Bakamovic via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> If it proves right, then allocating additional memory (like in your example) _after_ we finish with the libclang acitivites (disposal), memory consumption should _not_ increase. Expected is that the memory owned by the process will be reused

That doesn’t necessarily hold.  A typical modern memory allocator will have different pools for different-sized allocations and will provide a hint to the OS about whether the physical memory backing virtual regions can be reclaimed.  If you allocate with a different size to the ones that libclang has used, then you may end up with new zones being allocated from the OS for the memory allocator to reuse and if memory pressure is low then the OS may not recycle the physical pages that are backing free’d allocations (and if there is a lot of fragmentation, then you may have a very small number of allocations holding a lot of pages together).  

David




More information about the cfe-dev mailing list