4248
Why Does My IDL Session Grow And Never Shrink?
Exelis VIS receives many questions about how IDL manages memory use. Since memory is a central issue for any program, these questions are not very surprising.
This Help Article answers the question on "Why Does My IDL Session Grow And Never Shrink?"
Please see additional Help Articles for detailed information on how IDL uses memory:
Discussion:
When dynamic memory is allocated, malloc gets the required memory by making a request to the operating system to increase the size of the process. When memory is freed, it is placed on a free list. This memory is still part of the process, and is only available to future uses within the same program. IDL's memory use does not go down. You can satisfy yourself that IDL is in fact releasing the memory by using the
HELP, /MEMORY
command in IDL, but this does not make the memory available elsewhere.
The following lists the reasons why this memory is kept on a free list instead of being released back to the operating system:
- Only memory at the end of the process address space can be released to the operating system. Holes of unused memory in the middle cannot be released. This is the primary reason.
- For a malloc to be able to release memory at the end of a process, it must perform a larger amount of work. This makes memory allocation slower than it would be otherwise. This might be a bad idea if there is enough memory on the system to meet current needs (as is usually the case) because it will lead to poor performance with no visible gain for the effort thus expended.
- Most programs run briefly and then exit, releasing all memory back to the system. Time spent shrinking such a process is completely wasted. However, the memory allocator cannot know how long a given program will run.
- Growing and shrinking a process is an extremely expensive processes, whereas adding and removing memory from a free list is very cheap. Therefore, in cases where memory use swings wildly, it is better to spend the time and do the shrinking, but in cases where the memory use holds steadily, it is better to use the freelist and skip shrinking the process. The problem is that the memory allocator cannot know which situation it is facing, and therefore cannot perform this task optimally. Most malloc implementations do not shrink the process.
It is important to understand that this is a fundamental property of the system memory allocator, and not a behavior unique to IDL. All programs exhibit the same behavior. However, the effect is more noticeable with IDL due to the amount of memory that can be used, and the fact that IDL sessions can run for a long time.
Review on 12/31/2013 MM