GC - Garbage Collection for Stata variables (programmer command)

July 17, 2016 ยท View on GitHub

gc is just a simple counter based on -asarray()- that drops a variable once its counter reaches zero. Thus, it can be used for simple garbage collection, when trying to be careful with memory usage.

Example usage

sysuse auto

gc new
gc add price gear
gc add turn price trunk price
gc remove trunk price
gc report

sysuse auto, clear
gc new
gc add _all
gc add price turn
gc remove _all
gc report

Installation

With Stata 13+, type:

cap ado uninstall gc
net install gc, from(https://github.com/sergiocorreia/gc/raw/master/source/)

For older versions, first download and extract the zip file, and then run

ado uninstall gc
net install gc, from(SOME_FOLDER)

Where SOME_FOLDER is the folder that contains the stata.toc and related files.