Skip to content

Commit

Permalink
Remove @_memoized ivar from Minitest::Spec objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
peterzhu2118 committed Aug 23, 2023
1 parent dc30c4d commit 1c2c9dd
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 1c2c9dd

Please sign in to comment.