Routines (alphabetical) > Routines: H > HEAP_GC

# HEAP_GC

The HEAP_GC procedure performs manual garbage collection on heap variables. It searches all current IDL variables (including common blocks, widget user values, etc.) for pointers and object references and determines which heap variables have become inaccessible. Pointer heap variables are freed (via PTR_FREE) and all memory used by the heap variable is released. Object heap variables are destroyed (via OBJ_DESTROY), also freeing all used memory.

Note: If automatic garbage collection is enabled, heap variables are freed automatically when their reference counts reach zero. Automatic garbage collection is a more robust mechanism for finding and freeing orphaned heap variables than the older HEAP_GC procedure, since automatic garbage collection will only free heap variables that have no remaining references.

Note: See Automatic Garbage Collection for details.

The default action for HEAP_GC is to perform garbage collection on all heap variables regardless of type. Use the POINTER and OBJECT keywords to remove only specific types.

Note: Manual garbage collection is an expensive operation. When possible, applications should be written to avoid losing pointer and object references and avoid the need for garbage collection.

Note: HEAP_GC uses a recursive algorithm to search for unreferenced heap variables. If HEAP_GC is used to manage certain data structures, such as large linked lists, a potentially large number of operations may be pushed onto the system stack. If so many operations are pushed that the stack runs out of room, IDL will crash.

## Syntax

HEAP_GC [, /OBJ | , /PTR] [, /VERBOSE]

## Arguments

None.

## Keywords

### OBJ

Set this keyword to perform garbage collection on object heap variables only.

### PTR

Set this keyword to perform garbage collection on pointer heap variables only.

Note: Setting both the PTR and OBJ keywords is the same as setting neither.

### VERBOSE

If this keyword is set, HEAP_GC writes a one line description of each heap variable, in the format used by the HELP procedure, as the variable is destroyed. This is a debugging aid that can be used by program developers to check for heap variable leaks that need to be located and eliminated.

## Version History

5.0 | Introduced

## See Also

HEAP_FREE, HEAP_REFCOUNT