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

Fix memory leak for multiple runs in the same process #2987

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rspec/core/shared_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def find(lookup_contexts, name)
shared_example_groups[:main][name]
end

def reset
shared_example_groups.delete_if { |k, _| k != :main }
end
Copy link
Member

Choose a reason for hiding this comment

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

We would need a spec for this, as its important child shared example groups are still usable, its intentional they are not cleared (but unintentional that references to deleted example groups are kept around)


private

# TODO: remove this in RSpec 4. This exists only to support
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/core/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def reset
@sources_by_path.clear if defined?(@sources_by_path)
@syntax_highlighter = nil
@example_group_counts_by_spec_file = Hash.new(0)
@filtered_examples.clear
RSpec::Core::AnonymousExampleGroup.examples.clear
RSpec::Core::AnonymousExampleGroup.children.clear
shared_example_group_registry.reset
end

# @private
Expand Down