Basic garbage collection, plus optimizations.