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

Fix reference cycle that can result from objgraph.by_type #22

Merged
merged 1 commit into from Jul 28, 2015

Conversation

Projects
None yet
2 participants
@embray
Copy link
Contributor

embray commented Jul 27, 2015

This is perhaps a bit obscure, but was still biting me when trying to debug an unrelated reference cycle.
In the process of debugging I set gc.disable() so that I can ensure that I can find the (otherwise collectable) reference cycle before it's collected.

However, when running objgraph.by_type, it seems that a reference cycle can be created between the stack frame for by_type and itself by way of the objects list. Normally this would be cleaned up on the next garbage collector run, but since I'm leaving automatic garbage collection disabled it sticks around. Then when I run gc.get_referrers on one of the objects returned by by_type, I get back the huge objects list as one of its referrers since it's still being tracked.

Manually deleting the objects list at the end of by_type ensures that any reference cycles involving it are broken and can be cleaned up before any further inspection is performed on an object's referrers.

Ensure that reference cycles involving the objects list are broken wi…
…thout having to run the garbage collector on it.
@mgedmin

This comment has been minimized.

Copy link
Owner

mgedmin commented Jul 28, 2015

Thank you for the pull request!

mgedmin added a commit that referenced this pull request Jul 28, 2015

Merge pull request #22 from embray/fix-by-type-cycle
Fix reference cycle that can result from objgraph.by_type

@mgedmin mgedmin merged commit 0311889 into mgedmin:master Jul 28, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

mgedmin added a commit that referenced this pull request Jul 28, 2015

@mgedmin

This comment has been minimized.

Copy link
Owner

mgedmin commented Jul 28, 2015

Some other functions have the same problem: count(), typestats(). I'm fixing them too.

mgedmin added a commit that referenced this pull request Jul 28, 2015

@mgedmin

This comment has been minimized.

Copy link
Owner

mgedmin commented Jul 28, 2015

objgraph 2.0.1 is out with this fix.

@embray

This comment has been minimized.

Copy link
Contributor

embray commented Jul 28, 2015

Thanks!

@embray embray deleted the embray:fix-by-type-cycle branch Jul 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment