Clear MemoryCache for inline fixtures after context finishes#31
Merged
Conversation
After a context/suite finishes running, inline (anonymous) fixtures hold a MemoryCache reference that will never be used again. Named fixtures are shared and keep their memory. Releasing the MemoryCache for inline fixtures allows GC to reclaim the SQL statements and exposed mappings. - Extract FileCache and MemoryCache into their own classes - Add Cache#clear_memory to nil out @DaTa - Add Fixture#finish which calls clear_memory for anonymous fixtures - Hook finish into RSpec append_after(:context) and Minitest run_suite Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FileCacheandMemoryCacheout ofCacheinto their own classesCache#clear_memoryto nil out@data, allowing GC to reclaimMemoryCacheFixture#finishwhich callsclear_memoryonly for anonymous (inline) fixtures — named fixtures retain their cache since they may be shared across contextsfinishinto RSpecappend_after(:context)and Minitestrun_suiteThe key invariant: a finished fixture can still be mounted again — it re-hydrates from
FileCacheinstead of using the in-memory copy.Test plan
Cache#clear_memorynils out@dataclear_memory,exists?still returns true (falls through to file check)clear_memory,loadre-reads fromFileCacheFixture#finishclears memory for anonymous fixturesFixture#finishdoes not clear memory for named fixturesappend_after(:context)hook callsfinishrun_suitecallsfinishaftersuper🤖 Generated with Claude Code