Fix bug resulting from garbage collection