Repository navigation
Closed
Description
Expected Behavior
grails-fields plugin / FormFieldsTagLib / 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
FormFieldsTemplateServicegets registered as a spring bean (singleton)- Template lookup caching is enabled by default (
grails.plugin.fields.disableLookupCachenot explicitly specified) - We use, for example FormFieldsTaglib.field(...)
- For non-Domain objects,
FormFieldsTemplateService.findTemplateCached(...)- is invoked with a new
BeanPropertyAccessorImplinstance every time - and is annotated with
@Memoized(withoutmaxCacheSize) - that means Closure.memoize is usedThis variant will keep all cached values forever, i.e. till the closure gets garbage-collected.
- and that garbage collection is never happening because
FormFieldsTemplateServiceholds a reference to it
- and that garbage collection is never happening because
- is invoked with a new
the more complex the objects, the more memory is leaked (i.e. it is especially bad for command objects 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
https://github.com/zyro23/grails-core-16162
Version
7.2.2
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
jdaugherty commentedon Aug 21, 2026
@zyro23 from the best I can tell this has been a long standing issue? The Memorized caching looks to have been added several years ago. (I'm not saying we should not fix this, but trying to understand if this is a regression from Grails 7 or if it's pre-existing).
zyro23 commentedon Aug 21, 2026
i would agree that it is pre-existing, not specifically related to grails-7.
loddar commentedon Aug 31, 2026
I've registered the same issue. Typically killed by Kubernetes with OOMKilled. It's growing.
I've migrated the app from Grails 6 to Grails 7 in spring 2026. Since then the application has been unstable.
I'm using Grails 7.0.14
╔══ Logging-Diagnose ══════════════════════════════════════════╗
║ Java: 17.0.20 (Red Hat, Inc.)
║ JVM: OpenJDK 64-Bit Server VM 17.0.20+8-LTS
╚═════════════════════════════════════════════════════════╝
Grails application running at http://localhost:8080 in environment: production
Give TemplateLookupCachingSpec its own command fixture
Fix fields template lookup leak from accessor-keyed memoization