[PYTHON-CRYPTO] Erasing strings from memory?

Paul Swartz z3p at TWISTEDMATRIX.COM
Tue Nov 12 19:04:22 CET 2002

On Tue, Nov 12, 2002 at 12:53:57PM -0500, Jeremy Hylton wrote:
>   PS> I 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.

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

> I think the solution is to verify that it is not interned (ob_sstate),
> then recalculate the hash after zapping the string.

This sounds like a good idea.  Thanks for all the help/advice.

       Paul Swartz
(o_    http://www.twistedmatrix.com/users/z3p.twistd/  _o)
//\    z3p at twistedmatrix.com                           /\\
V_/_   AIM: z3penguin                                 _\_V->

Democracy is the recurrent suspicion that more than half the people are right
more than half of the time.

More information about the python-crypto mailing list