spring-projects / spring-projects/spring-framework
Reconsider using soft references for `ContextCache` in the TestContext framework
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
The idea of using soft references to implement a memory-sensitive ContextCache already came up a while ago in #12343. It was implemented and immediately reverted for not properly closing the evicted contexts. With finalize considered bad practice, there was no good way to implement that reliably back then.
However, that changed with JDK 9: The java.lang.ref.Cleaner interface can be used to clean up phantom reachable objects.
It would be a great improvement to have a memory-sensitive ContextCache. No longer having to use @DirtiesContext for memory-heavy tests would be a real charm.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the TestContext framework's ContextCache implementation and the earlier discussion in issue #12343. Investigate how Java 9's java.lang.ref.Cleaner could handle contexts evicted through soft references, and define completion around reliable cleanup of evicted contexts without requiring @DirtiesContext.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100