Skip to content

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

Merged
mgedmin merged 1 commit intomgedmin:masterfrom
embray:fix-by-type-cycle
Jul 28, 2015
Merged

Fix reference cycle that can result from objgraph.by_type#22
mgedmin merged 1 commit intomgedmin:masterfrom
embray:fix-by-type-cycle

Conversation

@embray
Copy link
Copy Markdown
Contributor

@embray 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.

…thout having to run the garbage collector on it.
@mgedmin
Copy link
Copy Markdown
Owner

mgedmin commented Jul 28, 2015

Thank you for the pull request!

mgedmin added a commit that referenced this pull request Jul 28, 2015
Fix reference cycle that can result from objgraph.by_type
@mgedmin mgedmin merged commit 0311889 into mgedmin:master Jul 28, 2015
mgedmin added a commit that referenced this pull request Jul 28, 2015
@mgedmin
Copy link
Copy Markdown
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
Copy link
Copy Markdown
Owner

mgedmin commented Jul 28, 2015

objgraph 2.0.1 is out with this fix.

@embray
Copy link
Copy Markdown
Contributor Author

embray commented Jul 28, 2015

Thanks!

@embray embray deleted the fix-by-type-cycle branch July 28, 2015 15:14
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