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

Remove reference cycles between MockFactory and ModelFactory. #918

Merged
merged 7 commits into from
May 2, 2019

Conversation

rainwoodman
Copy link
Contributor

This PR removes the reference cyels between MockFactory and ModelFactory.
I used objgraph to dump the back references in halotools/empirical_models/composite_models/tests/test_preloaded_models.py::test_hearin15

Before the PR:
before

After the PR:
after

Unfortunately this does not cure #917. Memory usage still increase after these cycles are cured. There must be other cycles that I haven't found yet.

The assumption is that mock is always a member of model anyways, so if
a mock is alive, then the model is too. This breaks a cyclic reference.
The assumption here is self.param_dict is never replaced
during the life cycle of the decorated function. It may be
a good idea to enforce that by replacing param_dict with a
read-only property.
@@ -276,12 +276,12 @@ def update_param_dict_decorator(self, component_model, func_name):
:ref:`param_dict_mechanism`
"""

def decorated_func(*args, **kwargs):
def decorated_func(*args, __param_dict__=self.param_dict, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rainwoodman - this line seems to be causing problems for a few builds. Any idea why? See https://travis-ci.org/astropy/halotools/jobs/399786150.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incompatible with Python 2.7. I pushed a fix.

@aphearin aphearin merged commit 6ce9862 into astropy:master May 2, 2019
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

Successfully merging this pull request may close these issues.

2 participants