Committed by
Gerrit Code Review
Fix Kryo serialization memory leak
Change-Id: I122cb811971aef1a70a73c3335b485125125c66b
Showing
1 changed file
with
4 additions
and
0 deletions
... | @@ -233,6 +233,7 @@ public final class KryoNamespace implements KryoFactory, KryoPool { | ... | @@ -233,6 +233,7 @@ public final class KryoNamespace implements KryoFactory, KryoPool { |
233 | */ | 233 | */ |
234 | public byte[] serialize(final Object obj, final int bufferSize) { | 234 | public byte[] serialize(final Object obj, final int bufferSize) { |
235 | ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE); | 235 | ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE); |
236 | + try { | ||
236 | Kryo kryo = borrow(); | 237 | Kryo kryo = borrow(); |
237 | try { | 238 | try { |
238 | kryo.writeClassAndObject(out, obj); | 239 | kryo.writeClassAndObject(out, obj); |
... | @@ -241,6 +242,9 @@ public final class KryoNamespace implements KryoFactory, KryoPool { | ... | @@ -241,6 +242,9 @@ public final class KryoNamespace implements KryoFactory, KryoPool { |
241 | } finally { | 242 | } finally { |
242 | release(kryo); | 243 | release(kryo); |
243 | } | 244 | } |
245 | + } finally { | ||
246 | + out.release(); | ||
247 | + } | ||
244 | } | 248 | } |
245 | 249 | ||
246 | /** | 250 | /** | ... | ... |
-
Please register or login to post a comment