Would you prefer using del or reassigning to None (garbage collecting)

后端 未结 3 1644
余生分开走
余生分开走 2020-12-18 17:49

Consider following code:

if value and self.fps_display is None:
    self.fps_display = clock.ClockDisplay()
elif not value and self.fps_display is not None:
         


        
3条回答
  •  有刺的猬
    2020-12-18 18:37

    There is no difference for garbage collection — in both cases a reference to object pointed to by self.fps_display will be released. Which one you should use depends on whether you want the name to still exist (albeit now pointing to a different object, None), or not.

提交回复
热议问题