cyberdelia / atomic

An atomic class that guarantees atomic updates to its contained value.
https://atomic.readthedocs.org
MIT License
24 stars 5 forks source link

Memory leak in Atomic.update function #9

Closed hstern closed 10 years ago

hstern commented 10 years ago

The atomic.update function leaks memory. To reproduce, run:

from atomic import Atomic
atomic = Atomic(0)
while True:
    atomic.update(lambda v: v + 1)

Watch your python process' memory footprint go up.

Python 2.7.2, atomic 0.6 downloaded from pypi.

hstern commented 10 years ago

Installation:

pip install atomic
Downloading/unpacking atomic
  Downloading atomic-0.6.tar.gz
  Running setup.py egg_info for package atomic

Installing collected packages: atomic
  Running setup.py install for atomic

    building 'atomic._reference' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c atomic/_reference.c -o build/temp.linux-x86_64-2.7/atomic/_reference.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/atomic/_reference.o -o build/lib.linux-x86_64-2.7/atomic/_reference.so
Successfully installed atomic
Cleaning up...
cyberdelia commented 10 years ago

Damn.

Atomic 0.7.1 fix this issue, but it's quite a departure from previous versions, see the releases notes: https://github.com/cyberdelia/atomic/releases/tag/0.7.0

There is no apparent memory leak when running this now:

from atomic import AtomicLong
atomic = AtomicLong(0)
while True:
    atomic += 1

I guess you're trying to use metrology, there is a fresh 0.10.0 that use this new version on pypi. There are two issues that might hurts with all this changes:

Thanks again for taking the time to report this, and trying to fix my crappy software in general :smile: