Fix a bug where an object was referenced after it was released.