Gson序列化對象時內存溢出

gson進行序列化時,會發生內存溢出的情況,一種情況是因為:在序列化對象中有logger對象。
這時需要設置logger的屬性
private transient final static Logger logger = LoggerFactory.getLogger(UnicomMobileBillInfoTemplate.class);

需要加上transient 屬性。

在stackoverflow上看到的一句話:
The transient keyword on a variable will ensure that the variable is not part of the serialized object when serializing. 
If your class is not serializable, nor a JPA entity (which uses the transient keyword to avoid storing variables in the database), removing it should be fine.
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容