The heap stores most, if not all, variable assignments. However, it only "garbage collects" memory that does not have a pointer pointing to it. Thus:
a = findgen(1000000)
will put 4MM new bytes of memory in the heap. A subsequent:
a = 0.0
will free 3,999,999 bytes of that memory from the heap. However:
a = ptr_new(findgen(1000000))
also puts 4MM new bytes of memory in the heap. The subsequent:
a = 0.0
does not free ANY memory. Now the memory has 4000001 bytes devoted to the activity of this variable named 'a'. You have to explicitly call:
ptr_free, a
before you reassign 'a', if you want to keep your heap memory "leak"-free.
James Jones
|