oop - how python manage object delete or destruction -
guys, rather new python , learning build gui application (with wypython). have question related object destruction in python. e.g. in myframe have onnew (create new document) , onopen (open file) method.
briefly, looks this.
def onnew self.data=datamodel() self.viewwindow=viewwindow(self.data) def onopen dlg = wx.filedialog(self, "open file", os.getcwd(), "", "*.*", wx.open) if dlg.showmodal() == wx.id_ok: self.data=datamodel.from_file(...) self.view=view(self.data)
now, want consider "if user click open or new again, after click either before."
so window classes, call self.viewwindow.destroy()
destry windows. data model object? if first call new: self.data=datamodel()
, call open , re-assign self.data=datamodel.from_file(...)
, old instance? need destruct myself or python manage destruction?
python has garbage collection. long don't have references old object hanging around collected.
as self.data = somethingelse
old self.data
won't have references (unless object had reference object's self.data
).
Comments
Post a Comment