Skip to content

memory leak in grails-fields FormFieldsTemplateService #16162

Closed

Description

@zyro23

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

  • 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(...)
  • For non-Domain objects, FormFieldsTemplateService.findTemplateCached(...)
    • is invoked with a new BeanPropertyAccessorImpl instance every time
    • and is annotated with @Memoized (without maxCacheSize) - that means Closure.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 objects with lots of constraints)

Steps To Reproduce

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

Activity

  1. jdaugherty commented on Aug 21, 2026

    @jdaugherty
    Contributor

    @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).

  2. zyro23 commented on Aug 21, 2026

    @zyro23
    ContributorAuthor

    i would agree that it is pre-existing, not specifically related to grails-7.

  3. loddar commented on Aug 31, 2026

    @loddar

    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

  4. added a commit that references this issue on Sep 4, 2026
    13bf440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions