widget: don't crash when deallocating in wrong order