Fixed bug where programs weren't being deallocated. See #4896.