FELIX-2635 Apply patch by Victor Antonovich (slightly modified to explicitly assign null after destroyal and adding try-catch around the destroy calls)