Memory Leak ['LBBW': checked]

Holger Joukl Holger.Joukl at LBBW.de
Wed Feb 25 09:18:33 EST 2004


>From this point of view, you never actually /destroy/ objects, you
just forget about them, and a __del__ method is a side-effect of
dropping the last reference to an object -- a slightly unnatural
action to have a side effect!

    This is obviously in contrast to C++, where you /do/ destroy
    objects (or in the case of local variables, it is clear when the
    object will be destroyed as a function of program flow).

I guess you are probably in the "reachable but not live" case of
memory leaks.

Instead of doing 'del alist' you might want to try 'del alist[:]' and
see if behaviour improves.

Cheers,
mwh

1) Aren´t  local variables destroyed as a function of program flow in
python, too?
At least if their refcount goes to zero (you do not hand a reference to
this local object
to the outside).

2) I am quite stunned by the del alist[:] thing:
>>> class foo:
...     def __del__(self):
...             print "foo.__del__"
...
>>> alist=[foo(), foo(), foo()]
>>> del alist[:]
foo.__del__
foo.__del__
foo.__del__
>>> alist
[]
alist[:] creates a shallow copy of alist, which is a new object. del then
decreases the refcount of this
temporary object, thus it is destroyed. But why is the original alist empty
after that, why are the
list elements destroyed?
Does that mean if a shallow copy of a list is created, the refcounts of the
elements in the list are not increased?

G
  Holger

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

    The contents of this  e-mail are confidential. If you are not the named
    addressee or if this transmission has been addressed to you in error,
    please notify the sender immediately and then delete this e-mail.  Any
    unauthorized copying and transmission is forbidden. E-Mail transmission
    cannot be guaranteed to be secure. If verification is required, please
    request a hard copy version.







More information about the Python-list mailing list