Remove and destroy object in a list -
Remove and destroy object in a list -
extending little on this question. removing object python list easy enough, i'm going have "busy" list -- frequent removals , frequent additions -- want guard against memory leaks.
will removing object list destroy object? (i'm assuming no.)
if assumption correct, how can remove list and destroy @ same time?
if matters, objects in question instances of class wrote. plan on creating objects "live" each time need insert new one, e.g.
mylist.insert(index,myclass(constructorparm1,constructorparm2))
so when later need delete of instances created way, want sure they're not gone list, gone period.
in cpython, objects automatically destroyed when reference count drops 0.
if delete entry list, reference count object in question decremented. not need special have destroyed, nor should seek to. if other reference object still exists, destroying object break other reference.
if want hold references object not stop object beingness garbage collected, utilize weakref
reference instead.
list object python-2.7 destroy
Comments
Post a Comment