首页 > 解决方案 > 弹簧启动执行器 InMemoryAuditEventRepository 的内存泄漏

问题描述

我在我的 spring-boot 应用程序中面临内存泄漏,并且在使用 Eclipse MAT 进行 heapdump 分析后,它指出了 spring boot 执行器中的潜在内存:精确地使用 InMemoryAuditEventRepository(审计事件)。

One instance of "org.springframework.boot.actuate.audit.InMemoryAuditEventRepository" loaded by "sun.misc.Launcher$AppClassLoader @ 0xe7020a30" occupies 210 676 784 (57,25%) bytes. The memory is accumulated in one instance of "org.springframework.boot.actuate.audit.AuditEvent[]" loaded by "sun.misc.Launcher$AppClassLoader @ 0xe7020a30".

Keywords
org.springframework.boot.actuate.audit.InMemoryAuditEventRepository
org.springframework.boot.actuate.audit.AuditEvent[]
sun.misc.Launcher$AppClassLoader @ 0xe7020a30

禁用此内存审计事件的最佳方法是什么:

  1. 删除 spring-boot-actor 依赖
  2. management.endpoints.enabled-by-default=true
  3. endpoints.auditevents.enabled=false

提前致谢

标签: spring-bootspring-boot-actuator

解决方案


遇到了同样的发现......

经过一番调查,发现这不是泄漏,而是 Spring Boot 存储了最后 4000 个安全(登录)审计事件。它会增长到那个数字,然后保持在那里......

您可以创建自己的实现,然后将其写入缓存或数据库,而不是将其保存在内存中。

参考


推荐阅读