Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in class AbstractClassGenerator.ClassLoaderData [SPR-17435] #21968

Open
spring-projects-issues opened this issue Oct 25, 2018 · 0 comments
Labels
in: core status: waiting-for-triage

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 25, 2018

Sylvère Richard opened SPR-17435 and commented

+How to reproduce:+

create several unit tests such as this one:

 

@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class MyTest {
  @Autowired
  MyCGLibProxiedService myService;

  @Test
  public void test1() {
    // test some stuff
  }
  @Test
  public void test2() {
     // test some stuff
  }
}

 

Because of the DirtiesContext, the application context test is closed and recreated after each test.

+Expected Behaviour:+

When running several unit tests such as the one above, the total memory needed to run the test suite should not increase as we add more tests.

In particular, when an application context is closed, the field generatedClasses (LoadingCache<AbstractClassGenerator, Object, Object>) of the class AbstractClassGenerator.ClassLoaderData should be cleared for that application context.

+Current Behaviour:+

The more unit tests we have, the more memory is required to run the test suite.

Indeed, the field generatedClasses caches instances of CglibAopProxy.ProxyCallbackFilter.

CglibAopProxy.ProxyCallbackFilter instance contains a reference to AdvisedSupport instance.

AdvisedSupport instance contains a reference to a closed AnnotationConfigApplicationContext.

Since all these references are strong one, it means that all closed instances of AnnotationConfigApplicationContext are never collected by the GC.

!image-2018-10-25-23-24-44-279.png!

+Possible Solutions:+

  • we could add a way to disable this cache when running unit tests.
  • we could listen to ContextClosedEvent and clear entries in the cache that reference a closed application context.
  • ...

 

 

 


Affects: 5.0.10

Attachments:

@spring-projects-issues spring-projects-issues added type: bug status: waiting-for-triage in: core and removed type: bug labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: waiting-for-triage
Projects
None yet
Development

No branches or pull requests

1 participant