Skip to content

Use soft or weak references for context caching in the TestContext framework [SPR-7687] #12343

Closed
@spring-projects-issues

Description

@spring-projects-issues

Eric Sirianni opened SPR-7687 and commented

We are using the Spring TestContext framework (SpringJUnit4ClassRunner) for JUnit test execution. We are hitting OutOfMemoryErrors when running a large number of tests in batch. The problem is that the ApplicationContext objects are building up in the ContextCache (org.springframework.test.context.ContextCache), consuming a large amount of memory.

We have worked around the problem by annotating @DirtiesContext on each JUnit test class.

However, it seems that this issue could be avoided if ContextCache wrapped its cached ApplicationContexts in WeakReferences. This seems to be a best practice when caching potentially large objects such as these.


Affects: 3.0.3

Issue Links:

Referenced from: commits 0cb22fc, d66d160

2 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions