move deallocation to a separate thread