zyro23 opened a new issue, #16162:
URL: https://github.com/apache/grails-core/issues/16162

   ### Expected Behavior
   
   FormFieldsTemplateService should not leak (heap-) memory for taglib 
invocations with non-domain objects if template lookup caching is enabled (or 
rather if it is not explicitly disabled).
   
   ### Actual Behaviour
   
   * `FormFieldsTemplateService` gets registered as a spring bean (singleton)
   * Template lookup caching is enabled by default 
(`grails.plugin.fields.disableLookupCache` not explicitly specified)
   * We use, for example 
[FormFieldsTaglib.field(...)](https://github.com/apache/grails-core/blob/v7.2.2/grails-fields/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy#L209)
   * For non-Domain objects, 
[`FormFieldsTemplateService.findTemplateCached(...)`](https://github.com/apache/grails-core/blob/v7.2.2/grails-fields/src/main/groovy/grails/plugin/formfields/FormFieldsTemplateService.groovy#L188-L191)
     * is invoked with a new `BeanPropertyAccessorImpl` instance every time
     * and is annotated with `@Memoized` (without `maxCacheSize`) - that means 
[Closure.memoize](https://docs.groovy-lang.org/docs/groovy-4.0.33/html/gapi/groovy/lang/Closure.html#memoize())
 is used
       > This variant will keep all cached values forever, i.e. till the 
closure gets garbage-collected.
       * and that garbage collection is never happening because 
`FormFieldsTemplateService` holds a reference to it
   
   the more complex the objects, the more memory is leaked (i.e. it is 
especially bad for command ojects with lots of constraints)
   
   ### Steps To Reproduce
   
   * run sample app (`bootRun`)
   * hit http://localhost:8080/demo/index
     * to speed things up, open it in multiple tabs in parallel or send 
concurrent get requests by some other means
   * see console, crashdump, heapdump
   
   ```
   java.lang.OutOfMemoryError: Java heap space
   Dumping heap to java_pid924064.hprof ...
   Heap dump file created [820046406 bytes in 3.710 secs]
   Aborting due to java.lang.OutOfMemoryError: Java heap space
   #
   # A fatal error has been detected by the Java Runtime Environment:
   #
   #  Internal Error (debug.cpp:271), pid=924064, tid=924156
   #  fatal error: OutOfMemory encountered: Java heap space
   #
   # JRE version: OpenJDK Runtime Environment Temurin-21.0.6+7 (21.0.6+7) 
(build 21.0.6+7-LTS)
   # Java VM: OpenJDK 64-Bit Server VM Temurin-21.0.6+7 (21.0.6+7-LTS, mixed 
mode, emulated-client, sharing, tiered, compressed oops, compressed class ptrs, 
g1 gc, linux-amd64)
   # Core dump will be written. Default location: Core dumps may be processed 
with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -F%F -- %E" 
(or dumping to /tmp/grails-fields-memleak-sample/core.924064)
   #
   # An error report file with more information is saved as:
   # /tmp/grails-fields-memleak-sample/hs_err_pid924064.log
   ```
   
   sample app will be referenced asap.
   
   ### Environment Information
   
   * ubuntu-24.04
   * jdk-21
   
   
   ### Example Application
   
   _No response_
   
   ### Version
   
   7.2.2


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to