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

given prevents function local types from being garbage collected #493

Closed
DRMacIver opened this issue Apr 9, 2017 · 1 comment
Closed
Assignees
Labels
bug something is clearly wrong here

Comments

@DRMacIver
Copy link
Member

A class defined inside a function should be suitable to be garbage collected, but given prevents that. Consider the following test:

 def test_local_types_are_garbage_collected():
      store = [None]

      def run_locally():
          class Test(object):
              @given(st.integers())
              def test(self, i):
                  pass
          store[0] = weakref(Test)
          Test().test()
      run_locally()
      del run_locally
      assert store[0] is not None
      gc.collect()
      assert store[0]() is None

This test fails, but passes if you remove the given and replace it with a normal method.

I believe the likely culprit is the strategy cache - I think the way we're constructing the arguments to the test function is causing something to hang on to a reference to self. This is probably a sign of a more general problem we should worry about if so.

@Zac-HD Zac-HD added the bug something is clearly wrong here label May 14, 2017
@Zac-HD
Copy link
Member

Zac-HD commented Feb 12, 2018

Trawling issues, I suspect that #833 is an example of the (hypothesised) more general problem. The strategy cache remains the top suspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

No branches or pull requests

2 participants