X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



12430 Rate this article:
2.8

How does IDL release Virtual Memory?

IDL does free its dynamic memory when it is done with it, and the IDL code has consistency checks that guard against memory leaks.

You can use the IDL command:

    HELP, /MEMORY

to see how much memory IDL has allocated. However, just because IDL frees its memory does not mean that its virtual address space will shrink and reduce its demand on the pagefile. In fact, it will not.

This seeming contradiction is due to the fact that IDL uses the C language malloc(3) and free(3) functions to allocate and free memory. When a process calls free, the freed memory is not returned to the operating system. It is simply placed into a free list. The next time malloc is called, it will try to satisfy the request from this free list before it asks the operating system for more memory. Thus, the process size (and demand on the pagefile) represents the high water mark of memory usage, not its current usage.

It might be nice if free would return memory to the operating system and reduce the amount of pagefile currently claimed by the process, but this is not done. To show why, consider an example in which a process allocates two arrays, and then frees the first one. Here is what would happen:

1) The first request causes malloc to request memory from the operating system. The process address space is enlarged and the request is satisfied.

2) The second request causes the address space to be extended again.

3) The process frees the first array. free() wants to return its memory to the operating system and shrink the process size, but it can't because the second array follows it in the virtual address space and this would leave a hole.

4) At this point, free() could try to make things work by copying the second array into the space occupied by the first, but then it would have to search the process address and fix up any pointers to the second array to point at the new location. This is impossible because there is no way to tell such pointers from unrelated memory locations that happen to contain the same bit pattern.

So, the dynamic memory is being freed, and it is gathering in the free list. Since each request is larger than the one before it, malloc makes the process grow to satisfy it, until the pagefile quota is hit. Arguably, malloc/free should be trying to coalesce the free list to make large memory chunks out of small ones, but for reasons known only to their author, it is not.

Now of course, the question is what can you do to help reduce this fragmentation?

To reduce fragmentation we recommend that you start IDL, then make one massive array as large as possible, i.e. an array which uses up most of your virtual memory. Next set it to the integer zero. Then continue with normal IDL usage. This will help reduce the problem.

NOTE:  Until IDL 8,  IDL heap variables such as pointers and objects had to be manually freed by the user using the PTR_FREE and OBJ_DESTROY command. In IDL 8 automatic garbage collection was added to complete this task automatically. 

Reviewed by JU 9/16/2014

1 comments on article "How does IDL release Virtual Memory?"

Avatar image

Alex Macgillivray

I notice the original date of this post is 1998. Is the information in this article still applicable to the current version of IDL (8.5.1 as I write this)?

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »