Fix possible crash after deleting objects.