Improve object destruction (bug #3286)