[BUG]JSON.toJSONString方法堆内存泄漏导致频繁FullGC
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
使用JSON.toJSONString方法序列化对象,发现应用频繁FullGC,堆内存2个G,其中com.alibaba.fastjson2.JSONWriterUTF16JDK8UF对象占用1.4G
### 环境信息
*请填写以下信息:*
- OS信息: [Linux version 5.10.134-16.1.al8.x86_64]
- JDK信息: [openjdk version "1.8.0_252"]
- 版本信息:[Fastjson2 2.0.52]
### 重现步骤
*如何操作可以重现该问题:*
使用 JSON.toJSONString 方法
```java
static final SerializeConfig SERIALIZE_CONFIG = new SerializeConfig(true);
static {
SERIALIZE_CONFIG.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss.SSS"));
SERIALIZE_CONFIG.put(Calendar.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss.SSS"));
}
JSON.toJSONString(obj, SERIALIZE_CONFIG, SerializerFeature.IgnoreErrorGetter, SerializerFeature.IgnoreNonFieldGetter);
```
### 期待的正确结果
正常输入JSON字符串,并且应用不会有内存泄漏
Contributor guide
Research direction
Start by reproducing the issue with JSON.toJSONString, the supplied SerializeConfig, and the IgnoreErrorGetter and IgnoreNonFieldGetter features on JDK 8. Inspect the resulting memory use around JSONWriterUTF16JDK8UF and verify that serialization still produces valid JSON without the reported heap growth or frequent Full GC.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100