[rules-users] Memory leak when deploying to Maven repository?

Sandjaja, Dominik dominik.sandjaja at it-motive.de
Tue Jun 10 09:01:43 EDT 2014


Hello everybody,

I use Drools to create rules from an external source and create an artifact from those rule strings, putting it into a local repository.

A minimalistic working example can be found at https://github.com/dadadom/MavenMemoryLeakMinimalExample

The code, taken from that example, is basically like this:

        ReleaseId releaseId = new ReleaseIdImpl("some:releaseid:1.0.0-SNAPSHOT");
        String rules = "rule \"testrule\ ... ";
        KieServices kServices = KieServices.Factory.get();
        KieFileSystem kfs = kServices.newKieFileSystem();
        kfs.write("src/main/resources/someBase/testrule", rules);
        kfs.generateAndWritePomXML(releaseId);
        String kmoduleXmlString = "<kmodule ... </kmodule>";
        kfs.writeKModuleXML(kmoduleXmlString.getBytes());

        KieModule kieModule = kServices.newKieBuilder(kfs).getKieModule();

        try {
            File pomFile = new File(System.getProperty("java.io.tmpdir"), "pom.xml");
            try (FileOutputStream fos = new FileOutputStream(pomFile)) {
                fos.write(KieBuilderImpl.generatePomXml(releaseId).getBytes()); fos.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
            final MavenRepository mavenRepository = MavenRepository.getMavenRepository();
            mavenRepository.deployArtifact(releaseId, (InternalKieModule) kieModule, pomFile);

When I call this method in a ServletContextListener in a Tomcat Server (version 7 or 8) and undeploy the application afterwards, I get a memory leak.
Tomcat tells me that the application has a memory leak:
The following web applications were stopped (reloaded, undeployed), but their
classes from previous runs are still loaded in memory, thus causing a memory
leak (use a profiler to confirm):
/mvntest

Looking at the memory dump with e.g. JProfiler, I can trace the dangling instances back to an object
  static INSTANCE of class org.drools.compiler.kie.builder.impl.KieRepositoryImpl

So it seems like there is something which I am either missing or which is a bug. I cannot find any .close() or .release() method or something alike on any of the involved objects ...

If anyone could give me a hint how to solve this problem, I'd be happy not to litter my memory no more :)

Regards and thanks
Dominik


...........................................................................
mit freundlichen Gr??en / kind regards
Dominik Sandjaja
Fon: +49 (0) 203 60878 183
Fax: +49 (0) 203 60878 222
e-mail: dominik.sandjaja at it-motive.de

it-motive AG
Zum Walkm?ller 6
47269 Duisburg
info at it-motive.de
http://www.it-motive.de
..............................................................................
Vorsitzender des Aufsichtsrats: Dr.-Ing. J?rgen Sturm
Vorstand: Horst-Dieter Deelmann (Vors.), Matthias Heming, Christoph Tim Klose
HRB 9207, Amtsgericht Duisburg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140610/5de00156/attachment.html 


More information about the rules-users mailing list