Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10773

Groovy 4 memory leak due to presumptuous caching in org.codehaus.groovy.vmplugin.v8.CacheableCallSite

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.5
    • 4.0.7
    • None
    • None
    • Java 1.8, 11, 14
      Groovy 4.0.3 4.0.4, 4.0.5
    • Important

    Description

      It looks like method handles caching is creating memory leaks in Groovy 4, because in addition to the method handle it is also storing the results of the  method execution in org.codehaus.groovy.vmplugin.v8.CacheableCallSite.latestHitMethodHandleWrapper

       

      These cached method handles are not subject to garbage collection. Since the cached handler is also storing the result of the method execution, which can be any arbitrary object, it will also prevent the object itself and any of its transitive properties from being garbage collected. In our case the method execution often produced very large maps which caused our prod servers to very quickly bog down and need restarts.

       

      I have tried this with Groovy 4.0.4 and 4.0.5, as well as Java 1.8, 11, and 14; all produced this memory leaks.

      However Groovy 3.0.5 did NOT produce this leak.

       

      I have attached a very simple Gradle project. It produces 5000 MemoryLeakItem objects. Nothing special about these objects themselves, just easy to find in VisualVM and heap dumps. A container object that does some basic dynamic method resolution via a methodMissing and a TestScript to run and pause execution, so a heap dump can be created or VisualVM inspected.

       

      To reproduce the leak:

      Run TestScript.groovy, and when it pauses for keyboard input, check VisualVM or a heap dump.

       

       

      Attachments

        1. build.gradle
          0.4 kB
          Val E
        2. heapdump.png
          165 kB
          Val E
        3. image-2022-09-29-13-21-57-256.png
          194 kB
          Val E
        4. image-2022-09-30-11-01-13-234.png
          111 kB
          Val E
        5. image-2022-09-30-11-05-57-860.png
          120 kB
          Val E
        6. image-2022-09-30-11-24-49-168.png
          119 kB
          Val E
        7. image-2022-11-23-21-27-08-558.png
          197 kB
          Val E
        8. image-2022-11-23-21-27-40-220.png
          93 kB
          Val E
        9. image-2022-11-23-21-28-26-645.png
          120 kB
          Val E
        10. MemLeakContainer.groovy
          1 kB
          Val E
        11. MemLeakItem.groovy
          0.2 kB
          Val E
        12. MemLeakTest.zip
          112 kB
          Val E
        13. screenshot-1.png
          6 kB
          Paul King
        14. screenshot-2.png
          8 kB
          Paul King
        15. screenshot-3.png
          5 kB
          Paul King
        16. screenshot-4.png
          205 kB
          Paul King
        17. TestScript.groovy
          0.4 kB
          Val E
        18. visualvm_mem_sampler.png
          103 kB
          Val E

        Issue Links

          Activity

            People

              paulk Paul King
              val235 Val E
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: