speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a memory leak in the Python library


From: Chris Brannon
Subject: a memory leak in the Python library
Date: Sat, 31 Jul 2010 05:38:39 -0500

I wrote:
> The solution is to simply execute
> del self._conn
> at the end of SSIPClient.close().  I think this is completely safe.

Also, self._conn should probably be a weak reference.  Otherwise, the
following snippet of code is not exception-safe.

c = SSIPClient('foo')
c.speak('Hello, world!')
# If c.speak raises an exception, this next statement is never executed, and
# thus c will never be collected:
c.close()

We might also want to think about adding the __enter__ and __exit__ methods
to SSIPClient, so that people can use the "with" statement described in
PEP 0343.  Python's "with" statement gives us  something
similar to RAII in C++.

-- Chris



reply via email to

[Prev in Thread] Current Thread [Next in Thread]