Added a workaround to avoid crashing when deallocating