Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampling MCMC objects lead to memory leak #167

Closed
tsh56 opened this issue Nov 5, 2017 · 3 comments
Closed

Sampling MCMC objects lead to memory leak #167

tsh56 opened this issue Nov 5, 2017 · 3 comments

Comments

@tsh56
Copy link

tsh56 commented Nov 5, 2017

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
Copy link
Member

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

@tsh56
Copy link
Author

tsh56 commented Nov 9, 2017

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
Copy link
Member

fonnesbeck commented Nov 18, 2017

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

Are you on current master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants