Skip to content

Commit

Permalink
Merge pull request #25 from Shopify/remove-memoized-ivar
Browse files Browse the repository at this point in the history
Remove @_memoized ivar from Minitest::Spec objects
  • Loading branch information
peterzhu2118 authored Aug 23, 2023
2 parents dc30c4d + 1c2c9dd commit 6925199
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/ruby_memcheck/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,18 @@
f.write($LOADED_FEATURES.join("\n"))
end

# We need to remove the @_memoized instance variable from Minitest::Spec
# objects because it holds a hash that contains memoized objects in `let`
# blocks, this can contain objects that will be reported as a memory leak.
if defined?(Minitest::Spec)
require "objspace"

ObjectSpace.each_object(Minitest::Spec) do |obj|
if obj.instance_variable_defined?(:@_memoized)
obj.remove_instance_variable(:@_memoized)
end
end
end

GC.start
end

0 comments on commit 6925199

Please sign in to comment.