A CDE Definition

(1) In a flash memory-based solid state drive (SSD), the garbage collection function improves write speed by erasing blocks of unused storage in the background, because flash memory requires blocks to be erased before they can be written. Having empty blocks available saves time when writing new data on the drive. See TRIM support and solid state drive.

(2) A software routine that searches memory for areas of inactive data and instructions in order to reclaim that space for the general memory pool (the heap). Operating systems may or may not provide this feature. For example, Windows does not do automatic garbage collection which requires that the programmer specifically deallocates memory in order to release it.

Move It to Disk or Deallocate
If a program continues to allocate memory for data buffers and eventually exceeds the physical memory capacity, the operating system then has to place parts of the program in virtual memory (on disk) in order to continue, which slows down processing. Writing the code to deallocate memory after a routine no longer needs it is a tedious task that programmers often forget to do. Java performs automatic garbage collection without programmer intervention, which eliminates this coding headache. See dynamic memory allocation, heap and Java.