[PYTHON-CRYPTO] Erasing strings from memory?

Jeremy Hylton jeremy at alum.mit.edu
Tue Nov 12 19:15:43 CET 2002


>>>>> "PS" == Paul Swartz <z3p at TWISTEDMATRIX.COM> writes:

  PS> On Tue, Nov 12, 2002 at 12:53:57PM -0500, Jeremy Hylton wrote: I
  PS> don't know.  I liked that the old code cleared all the
  PS> references to the string so I don't have to worry about
  PS> misc. references sitting around keeping this string in memory.
  PS> Does python really care if strings change on it?
  >>
  >> Yes.  Python depends in a lot of ways on strings being immutable.
  >> If the string gets stuffed in a dictionary and you modify it,
  >> you'll get unpredictable results.  The string can also be
  >> interned.  You can't modify a string in the intern table.

  PS> None of these strings will be a dictionary key.  They're either
  PS> incorporated into a hash, or parsed into an alternate form.  As
  PS> for interning, will they be interned if they're not a dictionary
  PS> key nor do I manually intern them?

We know they're not supposed to be used that way, but there's no way
to guarantee it.  Incautious use of this code could lead to bizarre,
impossible to understand behavior.  I think we both know that and are
willing to live with it.

Jeremy



More information about the python-crypto mailing list