pymc-devs / pymc2

THIS IS THE **OLD** PYMC PROJECT (VERSION 2). PLEASE USE PYMC INSTEAD:
http://pymc-devs.github.com/pymc/
Other
879 stars 229 forks source link

Sampling MCMC objects lead to memory leak #167

Closed tsh56 closed 6 years ago

tsh56 commented 6 years ago
import gc
import pymc

gc.collect()

foo= pymc.Bernoulli('foo', .3, value=[1])

model = pymc.Model([foo])

mcmc = pymc.MCMC(model)
mcmc.sample(10000, 2000, progress_bar=False)

obj = id(mcmc)
del foo
del model
del mcmc

gc.collect()
for o in gc.get_objects():
    if obj == id(o):
        print 'mcmc still exists'

The sample function attaches traces which introduces a circular reference means these object rely on gc to be freed. Unfortunately a numpy.array is part of the circular reference, so we are hitting this issue.

fonnesbeck commented 6 years ago

I can't replicate this here (Python 3.6 on macOS).

tsh56 commented 6 years ago

I just tested with python 3.6.3 on macOS. The output was "mcmc still exists" meaning that the object was not garbage collected even though all local references foo, model, and mcmc have been deleted.

fonnesbeck commented 6 years ago

I get no printed message, so I cannot replicate what you see.

Are you on current master?