{"id":504707,"date":"2026-11-25T09:44:44","date_gmt":"2026-11-25T06:44:44","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=504707"},"modified":"2026-11-25T09:44:44","modified_gmt":"2026-11-25T06:44:44","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=504707","title":{"rendered":"ObjectOutputStream \u0431\u0435\u0437 reset(): \u043a\u0430\u043a \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0438\u0445\u043e \u0441\u044a\u0435\u0434\u0430\u0435\u0442 \u0445\u0438\u043f"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>TL;DR:<\/strong> <code>ObjectOutputStream<\/code> \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u043f\u043e\u043a\u0430 \u0436\u0438\u0432 \u0441\u0430\u043c \u043f\u043e\u0442\u043e\u043a \u0438 \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u043b\u0438 <code>reset()<\/code>. \u0414\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0431\u0435\u0437 <code>reset()<\/code> \u2014 \u044d\u0442\u043e \u0443\u0442\u0435\u0447\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0430 \u0432 \u043f\u0440\u0438\u0434\u0430\u0447\u0443 \u0435\u0449\u0451 \u0438 \u0442\u0438\u0445\u0430\u044f \u043f\u043e\u0440\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h3>\u0421\u0438\u043c\u043f\u0442\u043e\u043c<\/h3>\n<p>\u041a\u0430\u0440\u0442\u0438\u043d\u0430 \u0437\u043d\u0430\u043a\u043e\u043c\u0430\u044f. \u0421\u0435\u0440\u0432\u0438\u0441 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 TCP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u0430 \u043d\u0451\u043c <code>ObjectOutputStream<\/code> \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0441\u0443\u0442\u043a\u0430\u043c\u0438 \u0433\u043e\u043d\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435, \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0437\u0435\u043b\u0451\u043d\u044b\u0435, \u043d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0410 \u043d\u0430 \u043f\u0440\u043e\u0434\u0435 \u0433\u0440\u0430\u0444\u0438\u043a old gen \u0440\u0430\u0441\u0442\u0451\u0442 \u043b\u0435\u0441\u0435\u043d\u043a\u043e\u0439: \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e full GC \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u043b\u0438\u043d\u0438\u044f \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439. \u0427\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u043e\u0432 \u0438\u043b\u0438 \u0434\u043d\u0435\u0439 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <code>OutOfMemoryError: Java heap space<\/code>, \u043f\u0440\u0438\u0447\u0451\u043c \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0430 <strong>\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439<\/strong> \u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u0433\u0434\u0435, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0432 \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u0445 \u0438 \u043d\u0435 \u0432 \u043a\u044d\u0448\u0430\u0445, \u0430 \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a JDK \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<h3>\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d ObjectOutputStream<\/h3>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f Java-\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0446\u0438\u043a\u043b\u044b \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438. \u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043d\u0438 \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u043d\u0435 \u043d\u0430 \u0434\u0432\u0435 \u043a\u043e\u043f\u0438\u0438.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <code>ObjectOutputStream<\/code> \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 <code>handles<\/code> \u0442\u0438\u043f\u0430 <code>ObjectOutputStream.HandleTable<\/code> \u2014 identity-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u00ab\u043e\u0431\u044a\u0435\u043a\u0442 \u2192 \u043d\u043e\u043c\u0435\u0440 (handle)\u00bb. \u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e\u0442\u043e\u043a \u0438\u0449\u0435\u0442 \u0435\u0433\u043e \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043f\u0440\u0438\u0447\u0451\u043c \u043f\u043e <code>System.identityHashCode<\/code> \u0438 <code>==<\/code>, \u0430 \u043d\u0435 \u043f\u043e <code>equals<\/code>. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0442\u0430\u043c, \u0432 \u043f\u043e\u0442\u043e\u043a \u0443\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u043e\u043d \u0441\u0430\u043c, \u0430 \u043c\u0430\u0440\u043a\u0435\u0440 <code>TC_REFERENCE<\/code> \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u2014 \u043f\u043e \u0441\u0443\u0442\u0438, \u00ab\u0441\u043c. \u043e\u0431\u044a\u0435\u043a\u0442 \u2116 42\u00bb. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0435\u0442, \u043f\u043e\u0442\u043e\u043a \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0435\u043c\u0443 \u043d\u043e\u0432\u044b\u0439 handle, \u043a\u043b\u0430\u0434\u0451\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0422\u0443\u0434\u0430 \u0436\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0441\u0442\u0440\u043e\u043a\u0438, \u043c\u0430\u0441\u0441\u0438\u0432\u044b, enum-\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (<code>ObjectStreamClass<\/code>). \u0420\u044f\u0434\u043e\u043c \u0436\u0438\u0432\u0451\u0442 \u0432\u0442\u043e\u0440\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u2014 <code>subs<\/code> \u0442\u0438\u043f\u0430 <code>ReplaceTable<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <code>writeReplace()<\/code> \u0438 <code>replaceObject()<\/code>.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442: <strong>\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0447\u0438\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430<\/strong>. \u041e\u043d\u0430 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0443 <code>writeObject()<\/code> \u0438 \u0436\u0438\u0432\u0451\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a. \u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e: \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u2014 \u00ab\u0432\u0441\u0451, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u2014 \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444\u00bb. \u041d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 <code>ObjectInputStream<\/code> \u0432\u0435\u0434\u0451\u0442 \u0437\u0435\u0440\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u043d\u043e\u043c\u0435\u0440 \u2192 \u043e\u0431\u044a\u0435\u043a\u0442\u00bb, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0442\u044c <code>TC_REFERENCE<\/code>.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0448\u0442\u0430\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044f \u043f\u043e\u0442\u043e\u043a, \u2014 <code>reset()<\/code>. \u041e\u043d \u043e\u0447\u0438\u0449\u0430\u0435\u0442 <code>handles<\/code> \u0438 <code>subs<\/code> \u0438 \u043f\u0438\u0448\u0435\u0442 \u0432 \u043f\u043e\u0442\u043e\u043a \u043c\u0430\u0440\u043a\u0435\u0440 <code>TC_RESET<\/code>; \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432 \u0435\u0433\u043e, <code>ObjectInputStream<\/code> \u0442\u043e\u0436\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0437 <code>reset()<\/code> \u0442\u0435\u0447\u0451\u0442 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c: \u0435\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0442\u0430\u0440\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f. \u041d\u0430 \u0441\u0445\u0435\u043c\u0435 \u043d\u0438\u0436\u0435 \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a \u0431\u0435\u0437 <code>reset()<\/code> \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0441\u0435\u0434\u0430\u0435\u0442 \u0432 <code>handles<\/code> \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u0438 \u0432 \u0437\u0435\u0440\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f, \u0430 \u043c\u0430\u0440\u043a\u0435\u0440 <code>TC_RESET<\/code> \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043e\u0431\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0437\u043e\u043c.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/cd\/01\/31\/cd01313a723fb48e7f9c0776308616b9.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/cd\/01\/31\/cd01313a723fb48e7f9c0776308616b9.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/cd\/01\/31\/cd01313a723fb48e7f9c0776308616b9.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h3>\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0443\u0442\u0435\u0447\u043a\u0443<\/h3>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0438\u0448\u0435\u0442 2 \u043c\u043b\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e ~1 \u041a\u0411 \u0432 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0451 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442. \u0421\u0435\u0442\u044c \u0438 \u0434\u0438\u0441\u043a \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u044c \u0440\u0430\u0441\u0442\u0451\u0442, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437-\u0437\u0430 \u0441\u0430\u043c\u043e\u0433\u043e <code>ObjectOutputStream<\/code>. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>reset<\/code> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 <code>reset()<\/code> \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>Leak.java \u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">import java.io.*;public class Leak {    static class Event implements Serializable {        long id;        byte[] payload = new byte[1024];        Event(long id) { this.id = id; }    }    \/\/ \u041f\u043e\u0442\u043e\u043a-\u00ab\u0447\u0451\u0440\u043d\u0430\u044f \u0434\u044b\u0440\u0430\u00bb: \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442    static class NullOut extends OutputStream {        public void write(int b) {}        public void write(byte[] b, int off, int len) {}    }    public static void main(String[] args) throws Exception {        boolean reset = args.length &gt; 0 &amp;&amp; args[0].equals(\"reset\");        ObjectOutputStream out = new ObjectOutputStream(                new BufferedOutputStream(new NullOut()));        Runtime rt = Runtime.getRuntime();        for (long i = 1; i &lt;= 2_000_000; i++) {            out.writeObject(new Event(i));            if (reset) out.reset();            if (i % 250_000 == 0) {                System.gc();                System.out.printf(\"%,d msgs: used heap %d MB%n\", i,                        (rt.totalMemory() - rt.freeMemory()) &gt;&gt; 20);            }        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043c\u0435\u0440\u044b \u044f \u0434\u0435\u043b\u0430\u043b \u043d\u0430 OpenJDK 21 \u043f\u043e\u0434 Linux. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0431\u0435\u0437 <code>reset()<\/code> \u2014 <code>java -Xmx512m Leak<\/code>:<\/p>\n<pre><code>250,000 msgs: used heap 263 MBException in thread \"main\" java.lang.OutOfMemoryError: Java heap spaceat Leak$Event.&lt;init&gt;(Leak.java:6)at Leak.main(Leak.java:23)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441 <code>reset()<\/code> \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u2014 <code>java -Xmx512m Leak reset<\/code>:<\/p>\n<pre><code>250,000 msgs: used heap 1 MB500,000 msgs: used heap 2 MB...2,000,000 msgs: used heap 2 MB<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u0430\u044f. 263 \u041c\u0411 \u043d\u0430 250 \u0442\u044b\u0441. \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u2014 \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 <code>Event<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0445 <code>byte[]<\/code>: \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u043b \u0432 <code>handles<\/code> \u0438 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u0430\u043c \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430, \u0445\u043e\u0442\u044f \u0438\u0437 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u0434\u0443\u0442 \u0434\u0435\u0441\u044f\u0442\u043a\u0430\u043c\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, OOM \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439, \u0438 \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043e \u043d\u0435 \u043b\u043e\u0432\u0438\u0442.<\/p>\n<h3>\u0411\u0430\u0433 \u043d\u043e\u043c\u0435\u0440 \u0434\u0432\u0430: \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0441\u0442\u0430\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0423 \u0442\u043e\u0439 \u0436\u0435 handle table \u0435\u0441\u0442\u044c \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043f\u043e\u0445\u0443\u0436\u0435 \u0443\u0442\u0435\u0447\u043a\u0438: <strong>\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0442\u043e\u0433\u043e \u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/strong>. \u041f\u043e\u0442\u043e\u043a \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u043f\u0438\u0448\u0435\u0442 \u043b\u0438\u0448\u044c \u00ab\u0441\u043c. \u043e\u0431\u044a\u0435\u043a\u0442 \u2116 N\u00bb, \u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e \u043b\u0435\u0433\u043a\u043e: \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0440\u0438\u0436\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 pipe-\u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<pre><code class=\"java\">Account acc = new Account();   \/\/ class Account implements Serializable { int balance; }for (int i = 1; i &lt;= 3; i++) {    acc.balance = i * 100;    out.writeObject(acc);    out.flush();    Account got = (Account) in.readObject();    System.out.println(\"sent \" + acc.balance + \", received \" + got.balance);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<details class=\"spoiler\">\n<summary>Stale.java \u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u043f\u043e\u0442\u043e\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">import java.io.*;public class Stale {    static class Account implements Serializable {        int balance;    }    public static void main(String[] args) throws Exception {        PipedOutputStream pipeOut = new PipedOutputStream();        PipedInputStream pipeIn = new PipedInputStream(pipeOut, 64 * 1024);        ObjectOutputStream out = new ObjectOutputStream(pipeOut);        out.flush(); \/\/ \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043f\u043e\u0442\u043e\u043a\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0439\u0442\u0438 \u0434\u043e ObjectInputStream        ObjectInputStream in = new ObjectInputStream(pipeIn);        Account acc = new Account();        for (int i = 1; i &lt;= 3; i++) {            acc.balance = i * 100;            out.writeObject(acc);            out.flush();            Account got = (Account) in.readObject();            System.out.println(\"sent \" + acc.balance + \", received \" + got.balance);        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code>sent 100, received 100sent 200, received 100sent 300, received 100<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0434\u043e\u0445\u043e\u0434\u044f\u0442 \u0432\u043e\u043e\u0431\u0449\u0435: \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u0438\u0439 \u0440\u0430\u0437 \u0432 \u043f\u043e\u0442\u043e\u043a \u0443\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u0440\u043a\u0435\u0440 <code>TC_REFERENCE<\/code> \u0438 \u043d\u043e\u043c\u0435\u0440 \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u0441\u0445\u0435\u043c\u0435.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/6f\/51\/71\/6f51719f8bff4d800986bd0245dda14f.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/6f\/51\/71\/6f51719f8bff4d800986bd0245dda14f.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/6f\/51\/71\/6f51719f8bff4d800986bd0245dda14f.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0422\u0430\u043a \u0431\u044b\u0432\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 mutable-DTO \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043a\u044d\u0448\u0430, \u0438 <code>reset()<\/code> \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043b\u0435\u0447\u0438\u0442 \u043e\u0431\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u0440\u0430\u0437\u0443. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0431\u0430\u0433 JDK, \u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435: \u0432 Javadoc \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e <code>reset()<\/code> \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0443\u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e <code>ObjectOutputStream<\/code>.<\/p>\n<h3>\u041a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u044d\u0442\u043e \u0432 \u043f\u0440\u043e\u0434\u0435<\/h3>\n<p>\u0423\u0442\u0435\u0447\u043a\u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u0430 \u0432 heap dump, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0441\u043a\u0430\u0442\u044c. \u041d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u0431\u0435\u0437 \u0434\u0430\u043c\u043f\u0430: <code>jcmd PID GC.class_histogram | head -20<\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u0438. \u0415\u0441\u043b\u0438 \u0432 \u0442\u043e\u043f\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0432\u0430\u0448\u0438 DTO, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0443\u043c\u0438\u0440\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438, \u0438 \u0438\u0445 \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0441\u0442\u0451\u0442 \u043e\u0442 \u0437\u0430\u043c\u0435\u0440\u0430 \u043a \u0437\u0430\u043c\u0435\u0440\u0443, \u044d\u0442\u043e \u043f\u043e\u0432\u043e\u0434 \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435. \u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a: \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435 full GC \u0440\u0430\u0441\u0442\u0451\u0442 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u043b\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0430 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0438\u043c \u0438 \u043f\u043e\u0442\u043e\u043a\u0430) \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0451 \u043a \u043d\u043e\u0440\u043c\u0435.<\/p>\n<p>\u0414\u0430\u043c\u043f \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>jcmd PID GC.heap_dump \/tmp\/heap.hprof<\/code>, \u0430 \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>-XX:+HeapDumpOnOutOfMemoryError<\/code>. \u0412 Eclipse MAT \u043e\u0442\u0447\u0451\u0442 <em>Leak Suspects<\/em> \u0438\u043b\u0438 <em>Dominator Tree<\/em> \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432 \u0442\u043e\u043f\u0435 \u043e\u0434\u0438\u043d <code>java.io.ObjectOutputStream<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0442\u043d\u0438 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442. \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0432\u0430\u0448\u0438\u0445 DTO \u043e\u0442\u043a\u0440\u044b\u0442\u044c <em>Path to GC Roots<\/em>, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 <code>ObjectOutputStream.handles<\/code> \u2192 <code>HandleTable.objs<\/code> \u2192 <code>Object[]<\/code> \u2192 \u0432\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442. \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430\u044f: <code>ObjectInputStream.handles<\/code> \u2192 <code>ObjectInputStream$HandleTable.entries<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442: \u043f\u0443\u0442\u044c \u0434\u043e GC root \u0432 Eclipse MAT<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/36\/6a\/1f\/366a1fda38b67d295b6895476d3603d6.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/36\/6a\/1f\/366a1fda38b67d295b6895476d3603d6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/36\/6a\/1f\/366a1fda38b67d295b6895476d3603d6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<p>\u0420\u0430\u0437\u0440\u0435\u0437\u0430\u0442\u044c \u044d\u0442\u0443 \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>reset()<\/code>: \u043e\u043d \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442 <code>objs<\/code>, \u0438 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u044b\u043c\u0438 \u0434\u043b\u044f GC.<\/p>\n<h3>\u041a\u0430\u043a \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c<\/h3>\n<p>\u0420\u0430\u0431\u043e\u0447\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0437\u0432\u0443\u0447\u0438\u0442 \u0442\u0430\u043a: <strong>\u043e\u0434\u043d\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 = \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444 = \u043e\u0434\u0438\u043d <\/strong><code><strong>reset()<\/strong><\/code>. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0441\u0431\u0440\u043e\u0441 \u0438\u0434\u0443\u0442 \u043f\u0430\u0440\u043e\u0439:<\/p>\n<pre><code class=\"java\">public synchronized void send(Message msg) throws IOException {    out.writeObject(msg);    out.reset();   \/\/ \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0438    out.flush();}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0432\u043e\u044f \u0446\u0435\u043d\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041f\u043e\u0434\u0445\u043e\u0434<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0423\u0442\u0435\u0447\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0426\u0435\u043d\u0430<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>reset()<\/code> \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e: \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u0440\u0443\u043f\u043d\u0435\u0435 \u043d\u0430 \u0434\u0435\u0441\u044f\u0442\u043a\u0438\u2013\u0441\u043e\u0442\u043d\u0438 \u0431\u0430\u0439\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>reset()<\/code> \u0440\u0430\u0437 \u0432 N \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 N<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441, \u043f\u0440\u0438\u0433\u043e\u0434\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>writeUnshared()<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0427\u0430\u0441\u0442\u0438\u0447\u043d\u043e<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043b\u044f \u043a\u043e\u0440\u043d\u044f \u2014 \u043d\u0435\u0442, \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u2014 \u0434\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442; \u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442\u0441\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041d\u043e\u0432\u044b\u0439 <code>ObjectOutputStream<\/code> \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435; \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044f\u0437\u0430\u043d \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 <code>ObjectInputStream<\/code>, \u0438\u043d\u0430\u0447\u0435 <code>StreamCorruptedException<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 <code>byte[]<\/code> + \u0441\u0432\u043e\u0439 framing<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u0438\u0448\u043d\u0435\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0437\u0430\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u043e <code>writeUnshared()<\/code> \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u041e\u043d \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439, \u043d\u043e \u0441\u043f\u0430\u0441\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0415\u0441\u043b\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u2014 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043e\u0431\u0449\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u2014 \u043e\u043d\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442 \u043e\u0441\u0435\u0434\u0430\u0442\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044e \u0432 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u043c \u0432\u0438\u0434\u0435. \u0421 \u043d\u043e\u0432\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0430\u044f \u0431\u0435\u0434\u0430: \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>ObjectInputStream<\/code> \u0447\u0438\u0442\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>STREAM_MAGIC<\/code>, \u0438 \u0441\u0442\u043e\u0438\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u043c \u0440\u0430\u0441\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 \u043e\u0434\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043f\u0430\u0434\u0430\u0435\u0442.<\/p>\n<p>\u0423 \u0441\u0430\u043c\u043e\u0433\u043e <code>reset()<\/code> \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438. \u0415\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 <code>writeObject()<\/code> \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u043d\u0430\u0447\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 <code>IOException: stream active<\/code>, \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432 \u043f\u043e\u0442\u043e\u043a \u043f\u0438\u0448\u0443\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0441\u0431\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439, \u0447\u0435\u0440\u0435\u0437 <code>synchronized<\/code> \u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 writer-\u043f\u043e\u0442\u043e\u043a, \u0438\u043d\u0430\u0447\u0435 <code>reset()<\/code> \u0432\u043a\u043b\u0438\u043d\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0438 \u0447\u0443\u0436\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430. \u041f\u043e \u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0434\u0435\u043b\u0430\u0442\u044c <code>reset()<\/code> \u043c\u0435\u0436\u0434\u0443 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430: \u0441\u0441\u044b\u043b\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u044f\u0442\u0441\u044f \u0432 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u043a\u043e\u043f\u0438\u0438. \u0417\u0430\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>TC_RESET<\/code> \u0441\u0430\u043c \u043e\u0447\u0438\u0441\u0442\u0438\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h3>\u0410 \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u0445<\/h3>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430 \u0434\u043b\u044f JDK: \u043b\u044e\u0431\u043e\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438, \u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0443\u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0412\u043e\u043f\u0440\u043e\u0441 \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u043e\u0447\u0438\u0449\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0412 <strong>Kryo<\/strong> \u043f\u0440\u0438 <code>setReferences(true)<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0441\u044b\u043b\u043e\u043a \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0433\u043e <code>writeObject<\/code>, \u0437\u0430 \u044d\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 <code>autoReset = true<\/code>. \u0413\u0440\u0430\u0431\u043b\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0440\u0430\u0434\u0438 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 <code>setAutoReset(false)<\/code> \u0438 \u0437\u0430\u0431\u044b\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>kryo.reset()<\/code> \u0432\u0440\u0443\u0447\u043d\u0443\u044e. <strong>Java RMI<\/strong> \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0443\u0442\u0438\u043b\u0438\u0442 \u0432\u0438\u0434\u0430 <code>serialize(Object): byte[]<\/code> \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>InstantiationUtil<\/code> \u0432\u043e Flink \u0438 <code>SerializationUtils<\/code> \u0432 Spring \u0438 Commons Lang \u2014 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0442\u0435\u0447\u043a\u0438 \u0442\u0430\u043c \u043d\u0435\u0442 \u043f\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p><strong>Kafka-\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b<\/strong> \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b: \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 <code>Serializer&lt;T&gt;.serialize()<\/code> \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 <code>byte[]<\/code> \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c. \u041e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u043e\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0435 \u00ab\u0434\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438\u00bb \u0437\u0430\u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d <code>ObjectOutputStream<\/code> \u043f\u043e\u0432\u0435\u0440\u0445 <code>ByteArrayOutputStream<\/code> \u0438 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0441\u043e\u043a\u0435\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430\u0445, \u0447\u0430\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445, \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0438 \u043b\u043e\u0433\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u0438\u043d <code>ObjectOutputStream<\/code>. \u0412\u043e\u0442 \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043d\u0430 \u0440\u0435\u0432\u044c\u044e:<\/p>\n<pre><code class=\"java\">\/\/ \u041f\u043b\u043e\u0445\u043e: \u043f\u043e\u0442\u043e\u043a \u0436\u0438\u0432\u0451\u0442 \u0432\u0435\u0447\u043d\u043e, \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440private final ByteArrayOutputStream buf = new ByteArrayOutputStream();private final ObjectOutputStream oos = new ObjectOutputStream(buf);public byte[] serialize(Object o) throws IOException {    buf.reset();           \/\/ \u0447\u0438\u0441\u0442\u0438\u0442 \u0431\u0430\u0439\u0442\u044b, \u041d\u041e \u043d\u0435 handle table    oos.writeObject(o);    \/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0432 oos.handles \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430    oos.flush();    return buf.toByteArray();}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c <code>reset()<\/code> \u0434\u0435\u043b\u0430\u044e\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0440\u0430\u0437\u043d\u043e\u0435: \u0431\u0430\u0439\u0442\u044b \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u0430 \u0433\u0440\u0430\u0444 \u2014 \u043d\u0435\u0442. \u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>byte[]<\/code> \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u0430, \u0430 \u043f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 \u0441\u0441\u044b\u043b\u043a\u0443 \u0432 \u043d\u0438\u043a\u0443\u0434\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p><code>ObjectOutputStream<\/code> \u2014 \u044d\u0442\u043e \u043d\u0435 \u00ab\u0442\u0440\u0443\u0431\u0430 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432\u00bb, \u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043e\u0434\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043d\u0438\u0442 \u0432\u0441\u0451, \u0447\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0448\u043b\u043e. \u0415\u0441\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439, \u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435, \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u043c\u0443 \u044f\u0432\u043d\u043e, \u0432\u044b\u0437\u0432\u0430\u0432 <code>reset()<\/code>.<\/p>\n<p>\u041d\u0430 \u0440\u0435\u0432\u044c\u044e \u044f \u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0449\u0435\u0439. \u0415\u0441\u043b\u0438 <code>ObjectOutputStream<\/code> \u0436\u0438\u0432\u0451\u0442 \u0434\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e <code>writeObject<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0434\u0442\u0438 <code>reset()<\/code>, \u0438 \u043f\u0440\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044f\u0445 \u044d\u0442\u0430 \u043f\u0430\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0439. \u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>ObjectOutputStream<\/code> \u043f\u043e\u0432\u0435\u0440\u0445 <code>ByteArrayOutputStream<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440, \u2014 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0439 \u043f\u043e\u0432\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u043e\u0442 \u0436\u0435 \u043f\u043e\u0442\u043e\u043a \u0431\u0435\u0437 <code>reset()<\/code>. \u0410 \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043b\u043e\u0432\u0438\u0442\u044c \u043f\u043e OOM, \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u0441\u0442\u043e\u0438\u0442 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>-XX:+HeapDumpOnOutOfMemoryError<\/code> \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 heap after GC, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0445\u0438\u043f\u0430.<\/p>\n<p>\u0418 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434: \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e Java-\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041f\u043e\u043c\u0438\u043c\u043e \u0443\u0442\u0435\u0447\u0435\u043a, \u0443 \u043d\u0435\u0451 \u0435\u0441\u0442\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0432\u0435\u0440\u0441\u0438\u0439, \u0430 JSON, Protobuf \u0438\u043b\u0438 Avro \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0442 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435.<\/p>\n<h3>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/java.base\/java\/io\/ObjectOutputStream.html\" rel=\"noopener nofollow\">Javadoc ObjectOutputStream (Java SE 21)<\/a> \u2014 \u043c\u0435\u0442\u043e\u0434\u044b <code>reset()<\/code>, <code>writeUnshared()<\/code><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/specs\/serialization\/protocol.html\" rel=\"noopener nofollow\">Java Object Serialization Specification, \u0433\u043b. 6 \u2014 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0442\u043e\u043a\u0430<\/a> \u2014 <code>TC_REFERENCE<\/code>, <code>TC_RESET<\/code><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/openjdk\/jdk\/blob\/master\/src\/java.base\/share\/classes\/java\/io\/ObjectOutputStream.java\" rel=\"noopener nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 ObjectOutputStream \u0432 OpenJDK<\/a> \u2014 <code>HandleTable<\/code>, <code>ReplaceTable<\/code><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1112048\/\">https:\/\/habr.com\/ru\/articles\/1112048\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR: ObjectOutputStream \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u043f\u043e\u043a\u0430 \u0436\u0438\u0432 \u0441\u0430\u043c \u043f\u043e\u0442\u043e\u043a \u0438 \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u043b\u0438 reset(). \u0414\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0431\u0435\u0437 reset() \u2014 \u044d\u0442\u043e \u0443\u0442\u0435\u0447\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0430 \u0432 \u043f\u0440\u0438\u0434\u0430\u0447\u0443 \u0435\u0449\u0451 \u0438 \u0442\u0438\u0445\u0430\u044f \u043f\u043e\u0440\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.\u0421\u0438\u043c\u043f\u0442\u043e\u043c\u041a\u0430\u0440\u0442\u0438\u043d\u0430 \u0437\u043d\u0430\u043a\u043e\u043c\u0430\u044f. \u0421\u0435\u0440\u0432\u0438\u0441 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 TCP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u0430 \u043d\u0451\u043c ObjectOutputStream \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0441\u0443\u0442\u043a\u0430\u043c\u0438 \u0433\u043e\u043d\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435, \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0437\u0435\u043b\u0451\u043d\u044b\u0435, \u043d\u0430 \u0441\u0442\u0435\u043d\u0434\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.\u0410 \u043d\u0430 \u043f\u0440\u043e\u0434\u0435 \u0433\u0440\u0430\u0444\u0438\u043a old gen \u0440\u0430\u0441\u0442\u0451\u0442 \u043b\u0435\u0441\u0435\u043d\u043a\u043e\u0439: \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e full GC \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u043b\u0438\u043d\u0438\u044f \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439. \u0427\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u043e\u0432 \u0438\u043b\u0438 \u0434\u043d\u0435\u0439 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 OutOfMemoryError: Java heap space, \u043f\u0440\u0438\u0447\u0451\u043c \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u0433\u0434\u0435, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0432 \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u0445 \u0438 \u043d\u0435 \u0432 \u043a\u044d\u0448\u0430\u0445, \u0430 \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a JDK \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d ObjectOutputStream\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f Java-\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0446\u0438\u043a\u043b\u044b \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438. \u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043d\u0438 \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u043d\u0435 \u043d\u0430 \u0434\u0432\u0435 \u043a\u043e\u043f\u0438\u0438.\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 ObjectOutputStream \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 handles \u0442\u0438\u043f\u0430 ObjectOutputStream.HandleTable \u2014 identity-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u00ab\u043e\u0431\u044a\u0435\u043a\u0442 \u2192 \u043d\u043e\u043c\u0435\u0440 (handle)\u00bb. \u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e\u0442\u043e\u043a \u0438\u0449\u0435\u0442 \u0435\u0433\u043e \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043f\u0440\u0438\u0447\u0451\u043c \u043f\u043e System.identityHashCode \u0438 ==, \u0430 \u043d\u0435 \u043f\u043e equals. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0442\u0430\u043c, \u0432 \u043f\u043e\u0442\u043e\u043a \u0443\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u043e\u043d \u0441\u0430\u043c, \u0430 \u043c\u0430\u0440\u043a\u0435\u0440 TC_REFERENCE \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u2014 \u043f\u043e \u0441\u0443\u0442\u0438, \u00ab\u0441\u043c. \u043e\u0431\u044a\u0435\u043a\u0442 \u2116 42\u00bb. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0435\u0442, \u043f\u043e\u0442\u043e\u043a \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0435\u043c\u0443 \u043d\u043e\u0432\u044b\u0439 handle, \u043a\u043b\u0430\u0434\u0451\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0422\u0443\u0434\u0430 \u0436\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0441\u0442\u0440\u043e\u043a\u0438, \u043c\u0430\u0441\u0441\u0438\u0432\u044b, enum-\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (ObjectStreamClass). \u0420\u044f\u0434\u043e\u043c \u0436\u0438\u0432\u0451\u0442 \u0432\u0442\u043e\u0440\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u2014 subs \u0442\u0438\u043f\u0430 ReplaceTable, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b writeReplace() \u0438 replaceObject().\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442: \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0447\u0438\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430. \u041e\u043d\u0430 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0443 writeObject() \u0438 \u0436\u0438\u0432\u0451\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a. \u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e: \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u2014 \u00ab\u0432\u0441\u0451, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u2014 \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444\u00bb. \u041d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 ObjectInputStream \u0432\u0435\u0434\u0451\u0442 \u0437\u0435\u0440\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u043d\u043e\u043c\u0435\u0440 \u2192 \u043e\u0431\u044a\u0435\u043a\u0442\u00bb, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0442\u044c TC_REFERENCE.\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0448\u0442\u0430\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044f \u043f\u043e\u0442\u043e\u043a, \u2014 reset(). \u041e\u043d \u043e\u0447\u0438\u0449\u0430\u0435\u0442 handles \u0438 subs \u0438 \u043f\u0438\u0448\u0435\u0442 \u0432 \u043f\u043e\u0442\u043e\u043a \u043c\u0430\u0440\u043a\u0435\u0440 TC_RESET; \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432 \u0435\u0433\u043e, ObjectInputStream \u0442\u043e\u0436\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0437 reset() \u0442\u0435\u0447\u0451\u0442 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c: \u0435\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0442\u0430\u0440\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f. \u041d\u0430 \u0441\u0445\u0435\u043c\u0435 \u043d\u0438\u0436\u0435 \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a \u0431\u0435\u0437 reset() \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0441\u0435\u0434\u0430\u0435\u0442 \u0432 handles \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u0438 \u0432 \u0437\u0435\u0440\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f, \u0430 \u043c\u0430\u0440\u043a\u0435\u0440 TC_RESET \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043e\u0431\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0437\u043e\u043c.\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0443\u0442\u0435\u0447\u043a\u0443\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0438\u0448\u0435\u0442 2 \u043c\u043b\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e ~1 \u041a\u0411 \u0432 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0451 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442. \u0421\u0435\u0442\u044c \u0438 \u0434\u0438\u0441\u043a \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u044c \u0440\u0430\u0441\u0442\u0451\u0442, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437-\u0437\u0430 \u0441\u0430\u043c\u043e\u0433\u043e ObjectOutputStream. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 reset \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 reset() \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.Leak.java \u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430import java.io.*;public class Leak {    static class Event implements Serializable {        long id;        byte[] payload = new byte[1024];        Event(long id) { this.id = id; }    }    \/\/ \u041f\u043e\u0442\u043e\u043a-\u00ab\u0447\u0451\u0440\u043d\u0430\u044f \u0434\u044b\u0440\u0430\u00bb: \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442    static class NullOut extends OutputStream {        public void write(int b) {}        public void write(byte[] b, int off, int len) {}    }    public static void main(String[] args) throws Exception {        boolean reset = args.length &gt; 0 &amp;&amp; args[0].equals(&#171;reset&#187;);        ObjectOutputStream out = new ObjectOutputStream(                new BufferedOutputStream(new NullOut()));        Runtime rt = Runtime.getRuntime();        for (long i = 1; i &lt;= 2_000_000; i++) {            out.writeObject(new Event(i));            if (reset) out.reset();            if (i % 250_000 == 0) {                System.gc();                System.out.printf(&#171;%,d msgs: used heap %d MB%n&#187;, i,                        (rt.totalMemory() &#8212; rt.freeMemory()) &gt;&gt; 20);            }        }    }}\u0417\u0430\u043c\u0435\u0440\u044b \u044f \u0434\u0435\u043b\u0430\u043b \u043d\u0430 OpenJDK 21 \u043f\u043e\u0434 Linux. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0431\u0435\u0437 reset() \u2014 java -Xmx512m Leak:250,000 msgs: used heap 263 MBException in thread &#171;main&#187; java.lang.OutOfMemoryError: Java heap spaceat Leak$Event.&lt;init&gt;(Leak.java:6)at Leak.main(Leak.java:23)\u0422\u0435\u043f\u0435\u0440\u044c \u0441 reset() \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u2014 java -Xmx512m Leak reset:250,000 msgs: used heap 1 MB500,000 msgs: used heap 2 MB&#8230;2,000,000 msgs: used heap 2 MB\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u0430\u044f. 263 \u041c\u0411 \u043d\u0430 250 \u0442\u044b\u0441. \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u2014 \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 Event \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0445 byte[]: \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u043b \u0432 handles \u0438 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u0430\u043c \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430, \u0445\u043e\u0442\u044f \u0438\u0437 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u0434\u0443\u0442 \u0434\u0435\u0441\u044f\u0442\u043a\u0430\u043c\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, OOM \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439, \u0438 \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043e \u043d\u0435 \u043b\u043e\u0432\u0438\u0442.\u0411\u0430\u0433 \u043d\u043e\u043c\u0435\u0440 \u0434\u0432\u0430: \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0441\u0442\u0430\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\u0423 \u0442\u043e\u0439 \u0436\u0435 handle table \u0435\u0441\u0442\u044c \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043f\u043e\u0445\u0443\u0436\u0435 \u0443\u0442\u0435\u0447\u043a\u0438: \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0442\u043e\u0433\u043e \u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u041f\u043e\u0442\u043e\u043a \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u043f\u0438\u0448\u0435\u0442 \u043b\u0438\u0448\u044c \u00ab\u0441\u043c. \u043e\u0431\u044a\u0435\u043a\u0442 \u2116 N\u00bb, \u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e \u043b\u0435\u0433\u043a\u043e: \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0440\u0438\u0436\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 pipe-\u043f\u043e\u0442\u043e\u043a\u043e\u0432.Account acc = new Account();   \/\/ class Account implements Serializable { int balance; }for (int i = 1; i &lt;= 3; i++) {    acc.balance = i * 100;    out.writeObject(acc);    out.flush();    Account got = (Account) in.readObject();    System.out.println(&#171;sent &#187; + acc.balance + &#171;, received &#187; + got.balance);}Stale.java \u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u043f\u043e\u0442\u043e\u043a\u043e\u0432import java.io.*;public class Stale {    static class Account implements Serializable {        int balance;    }    public static void main(String[] args) throws Exception {        PipedOutputStream pipeOut = new PipedOutputStream();        PipedInputStream pipeIn = new PipedInputStream(pipeOut, 64 * 1024);        ObjectOutputStream out = new ObjectOutputStream(pipeOut);        out.flush(); \/\/ \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043f\u043e\u0442\u043e\u043a\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u043e\u0439\u0442\u0438 \u0434\u043e ObjectInputStream        ObjectInputStream in = new ObjectInputStream(pipeIn);        Account acc = new Account();        for (int i = 1; i &lt;= 3; i++) {            acc.balance = i * 100;            out.writeObject(acc);            out.flush();            Account got = (Account) in.readObject();            System.out.println(&#171;sent &#187; + acc.balance + &#171;, received &#187; + got.balance);        }    }}\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:sent 100, received 100sent 200, received 100sent 300, received 100\u041d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0434\u043e\u0445\u043e\u0434\u044f\u0442 \u0432\u043e\u043e\u0431\u0449\u0435: \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u0438\u0439 \u0440\u0430\u0437 \u0432 \u043f\u043e\u0442\u043e\u043a \u0443\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u0440\u043a\u0435\u0440 TC_REFERENCE \u0438 \u043d\u043e\u043c\u0435\u0440 \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u0441\u0445\u0435\u043c\u0435.\u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0422\u0430\u043a \u0431\u044b\u0432\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 mutable-DTO \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043a\u044d\u0448\u0430, \u0438 reset() \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043b\u0435\u0447\u0438\u0442 \u043e\u0431\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u0440\u0430\u0437\u0443. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0431\u0430\u0433 JDK, \u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435: \u0432 Javadoc \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e reset() \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0443\u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e ObjectOutputStream.\u041a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u044d\u0442\u043e \u0432 \u043f\u0440\u043e\u0434\u0435\u0423\u0442\u0435\u0447\u043a\u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u0430 \u0432 heap dump, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0441\u043a\u0430\u0442\u044c. \u041d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u0431\u0435\u0437 \u0434\u0430\u043c\u043f\u0430: jcmd PID GC.class_histogram | head -20 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u0438. \u0415\u0441\u043b\u0438 \u0432 \u0442\u043e\u043f\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0432\u0430\u0448\u0438 DTO, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0443\u043c\u0438\u0440\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438, \u0438 \u0438\u0445 \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0441\u0442\u0451\u0442 \u043e\u0442 \u0437\u0430\u043c\u0435\u0440\u0430 \u043a \u0437\u0430\u043c\u0435\u0440\u0443, \u044d\u0442\u043e \u043f\u043e\u0432\u043e\u0434 \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435. \u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a: \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435 full GC \u0440\u0430\u0441\u0442\u0451\u0442 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u043b\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0430 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0438\u043c \u0438 \u043f\u043e\u0442\u043e\u043a\u0430) \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0451 \u043a \u043d\u043e\u0440\u043c\u0435.\u0414\u0430\u043c\u043f \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 jcmd PID GC.heap_dump \/tmp\/heap.hprof, \u0430 \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c -XX:+HeapDumpOnOutOfMemoryError. \u0412 Eclipse MAT \u043e\u0442\u0447\u0451\u0442 Leak Suspects \u0438\u043b\u0438 Dominator Tree \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432 \u0442\u043e\u043f\u0435 \u043e\u0434\u0438\u043d java.io.ObjectOutputStream, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0442\u043d\u0438 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442. \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 \u0432\u0430\u0448\u0438\u0445 DTO \u043e\u0442\u043a\u0440\u044b\u0442\u044c Path to GC Roots, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 ObjectOutputStream.handles \u2192 HandleTable.objs \u2192 Object[] \u2192 \u0432\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442. \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430\u044f: ObjectInputStream.handles \u2192 ObjectInputStream$HandleTable.entries.\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442: \u043f\u0443\u0442\u044c \u0434\u043e GC root \u0432 Eclipse MAT\u0420\u0430\u0437\u0440\u0435\u0437\u0430\u0442\u044c \u044d\u0442\u0443 \u0446\u0435\u043f\u043e\u0447\u043a\u0443, \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e reset(): \u043e\u043d \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442 objs, \u0438 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u044b\u043c\u0438 \u0434\u043b\u044f GC.\u041a\u0430\u043a \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0420\u0430\u0431\u043e\u0447\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0437\u0432\u0443\u0447\u0438\u0442 \u0442\u0430\u043a: \u043e\u0434\u043d\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 = \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444 = \u043e\u0434\u0438\u043d reset(). \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0441\u0431\u0440\u043e\u0441 \u0438\u0434\u0443\u0442 \u043f\u0430\u0440\u043e\u0439:public synchronized void send(Message msg) throws IOException {    out.writeObject(msg);    out.reset();   \/\/ \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0438    out.flush();}\u0415\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0432\u043e\u044f \u0446\u0435\u043d\u0430:\u041f\u043e\u0434\u0445\u043e\u0434\u0423\u0442\u0435\u0447\u043a\u0430\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\u0426\u0435\u043d\u0430reset() \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u041d\u0435\u0442\u041d\u0435\u0442\u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e: \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u0440\u0443\u043f\u043d\u0435\u0435 \u043d\u0430 \u0434\u0435\u0441\u044f\u0442\u043a\u0438\u2013\u0441\u043e\u0442\u043d\u0438 \u0431\u0430\u0439\u0442reset() \u0440\u0430\u0437 \u0432 N \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 N\u0414\u0430\u041a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441, \u043f\u0440\u0438\u0433\u043e\u0434\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432writeUnshared()\u0427\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0414\u043b\u044f \u043a\u043e\u0440\u043d\u044f \u2014 \u043d\u0435\u0442, \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u2014 \u0434\u0430\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442; \u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442\u0441\u044f\u041d\u043e\u0432\u044b\u0439 ObjectOutputStream \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u041d\u0435\u0442\u041d\u0435\u0442\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435; \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044f\u0437\u0430\u043d \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 ObjectInputStream, \u0438\u043d\u0430\u0447\u0435 StreamCorruptedException\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 byte[] + \u0441\u0432\u043e\u0439 framing\u041d\u0435\u0442\u041d\u0435\u0442\u041b\u0438\u0448\u043d\u0435\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0437\u0430\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u041f\u0440\u043e writeUnshared() \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u041e\u043d \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439, \u043d\u043e \u0441\u043f\u0430\u0441\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0415\u0441\u043b\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u2014 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043e\u0431\u0449\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u2014 \u043e\u043d\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442 \u043e\u0441\u0435\u0434\u0430\u0442\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044e \u0432 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u043c \u0432\u0438\u0434\u0435. \u0421 \u043d\u043e\u0432\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0430\u044f \u0431\u0435\u0434\u0430: \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 ObjectInputStream \u0447\u0438\u0442\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a STREAM_MAGIC, \u0438 \u0441\u0442\u043e\u0438\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u043c \u0440\u0430\u0441\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 \u043e\u0434\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043f\u0430\u0434\u0430\u0435\u0442.\u0423 \u0441\u0430\u043c\u043e\u0433\u043e reset() \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438. \u0415\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 writeObject() \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u043d\u0430\u0447\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 IOException: stream active, \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-504707","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/504707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=504707"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/504707\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=504707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=504707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=504707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}