Code Monkey home page Code Monkey logo

Comments (3)

phaas avatar phaas commented on July 26, 2024

Fixing this should be as simple as changing the map to a WeakHashMap, which will allow for garbage collection to proceed.

from jadira.

phaas avatar phaas commented on July 26, 2024

A manual workaround (e.g. using a @PreDestroy spring hook):

import java.lang.reflect.Field;
import java.util.HashMap;

import javax.annotation.PreDestroy;

import org.jadira.usertype.spi.shared.ConfigurationHelper;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HibernateConfiguration {

   /**
    * Jadira's shared configuration helper records the "JDBC 4.2" compatibility for each
    * session manager that it's registered with.
    * <p>
    * Unfortunately, the configuration stores the SessionManager as the key in a static hash map,
    * which retains it indefinitely.
    * <p>
    * This is generally not a huge issue when running a web app, but during unit tests where context
    * are often created and destroyed, we leak a significant amount of memory (approx. 20mb/test execution),
    * resulting in the JVM running out of memory and slowly grinding to a hold
    */
   @PreDestroy
   public void clearOutJadiraConfigurationMap() {
      try {
         final Field map = ConfigurationHelper.class.getDeclaredField("DEFAULT_USEJDBC42");
         map.setAccessible(true);
         Object value = map.get(null);

         ((HashMap) value).clear();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

from jadira.

phaas avatar phaas commented on July 26, 2024

Looks like this is a duplicate of #26

from jadira.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.