Skip to content

Commit

Permalink
fix memory leak (#10231)
Browse files Browse the repository at this point in the history
  • Loading branch information
icodening committed Jun 29, 2022
1 parent cd6b63d commit 7a0c805
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@
*/
public class Hessian2ObjectInput implements ObjectInput, Cleanable {

private static ThreadLocal<Hessian2Input> INPUT_TL = ThreadLocal.withInitial(() -> {
Hessian2Input h2i = new Hessian2Input(null);
h2i.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
h2i.setCloseStreamOnClose(true);
return h2i;
});

private final Hessian2Input mH2i;

public Hessian2ObjectInput(InputStream is) {
mH2i = INPUT_TL.get();
mH2i.init(is);
mH2i = new Hessian2Input(is);
mH2i.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
mH2i.setCloseStreamOnClose(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@
*/
public class Hessian2ObjectOutput implements ObjectOutput, Cleanable {

private static ThreadLocal<Hessian2Output> OUTPUT_TL = ThreadLocal.withInitial(() -> {
Hessian2Output h2o = new Hessian2Output(null);
h2o.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
h2o.setCloseStreamOnClose(true);
return h2o;
});

private final Hessian2Output mH2o;

public Hessian2ObjectOutput(OutputStream os) {
mH2o = OUTPUT_TL.get();
mH2o.init(os);
mH2o = new Hessian2Output(os);
mH2o.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
mH2o.setCloseStreamOnClose(true);
}

@Override
Expand Down

0 comments on commit 7a0c805

Please sign in to comment.