fix memory bug in gc. probably fixes #3131