OpenJPA
  1. OpenJPA
  2. OPENJPA-2042

Diagnostics for Application Managed EntityManagerFactory leaks.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.4, 1.2.2, 2.0.1, 2.1.0
    • Fix Version/s: 1.2.3, 2.2.0
    • Component/s: None
    • Labels:
      None

      Description

      EntityManagerFactories can be leaked if they are created with the JSE bootstrap Persistence class and are never closed, causing an OutOfMemoryException.

      One possibility may be to log a warning or otherwise alert the developer when the number of unclosed EMF's reaches a certain threshold. An extra step could be taken here to track where the EMF's are being opened and which ones aren't being closed as to show the developer exactly where in the code the problem is occurring.

      There may be a possibility to eliminate this leak by making the references to the EMF's weak and let the garbage collector clean up the unclosed EMF's. However, in the case that other objects are being leaked as well, this change may make it harder to detect such leaks.

      I ran a simple test that creates a EMF from Persistence. It then creates and closes an EntityManger. A new EMF is then created without closing the old one, effectively "leaking" it. As expected, this results in an OutOfMemoryException. When using weak references on the EMF's, I was able to get the test to run all night without a trace of any heap growth. However, this is only a very simple test and a test with more Entities/Configurations/etc. may result in heap growth due to other objects being leaked(as mentioned earlier). My test case is attached.

      For comparison, I tried the same test on Hibernate and EclipseLink. Hibernate runs into the same OutOfMemoryException. EclipseLink does not.

      1. TestEMFMemoryLeak.java
        2 kB
        Jacob Nowosatka
      2. OPENJPA-2042.patch
        1 kB
        Jacob Nowosatka

        Activity

        Jacob Nowosatka created issue -
        Jacob Nowosatka made changes -
        Field Original Value New Value
        Attachment TestEMFMemoryLeak.java [ 12490976 ]
        Jacob Nowosatka made changes -
        Attachment TestEMFMemoryLeak.java [ 12490976 ]
        Jacob Nowosatka made changes -
        Attachment TestEMFMemoryLeak.java [ 12490977 ]
        Jacob Nowosatka made changes -
        Attachment TestEMFMemoryLeak.java [ 12490977 ]
        Jacob Nowosatka made changes -
        Attachment TestEMFMemoryLeak.java [ 12491207 ]
        Jacob Nowosatka made changes -
        Attachment OPENJPA-2042.patch [ 12493363 ]
        Michael Dick made changes -
        Assignee Michael Dick [ mikedd ]
        Michael Dick made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2.0 [ 12315910 ]
        Resolution Fixed [ 1 ]
        Michael Dick made changes -
        Affects Version/s 2.1.0 [ 12314542 ]
        Affects Version/s 2.0.1 [ 12314532 ]
        Affects Version/s 1.2.2 [ 12313681 ]
        Affects Version/s 1.0.4 [ 12313301 ]
        Rick Curtis made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Assignee Michael Dick [ mikedd ] Rick Curtis [ curtisr7 ]
        Rick Curtis made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Albert Lee made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Jeremy Bauer made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Jeremy Bauer made changes -
        Fix Version/s 1.2.3 [ 12314517 ]
        Jeremy Bauer made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Rick Curtis
            Reporter:
            Jacob Nowosatka
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development