Mercurial > hg > Members > tatsuki > Alice
changeset 122:d5d9ca4cbe87 working fish-example-worked
fix memory leak!
author | one |
---|---|
date | Fri, 27 Jul 2012 02:04:45 +0900 |
parents | bddb8be357f6 |
children | 2c00375c57b1 |
files | src/alice/codesegment/OutputDataSegment.java src/alice/daemon/OutboundTcpConnection.java src/alice/datasegment/Receiver.java |
diffstat | 3 files changed, 7 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/codesegment/OutputDataSegment.java Fri Jul 27 00:46:01 2012 +0900 +++ b/src/alice/codesegment/OutputDataSegment.java Fri Jul 27 02:04:45 2012 +0900 @@ -11,6 +11,7 @@ public class OutputDataSegment { public CodeSegment cs; + private static MessagePack MSGPACK = new MessagePack(); public OutputDataSegment(CodeSegment codeSegment) { this.cs = codeSegment; @@ -49,18 +50,16 @@ } public <T> void put(String managerKey, String key, T val) { - MessagePack msgpack = new MessagePack(); try { - DataSegment.get(managerKey).put(key, msgpack.unconvert(val), cs); + DataSegment.get(managerKey).put(key, MSGPACK.unconvert(val), cs); } catch (IOException e) { e.printStackTrace(); } } public <T> void update(String managerKey, String key, T val) { - MessagePack msgpack = new MessagePack(); try { - DataSegment.get(managerKey).update(key, msgpack.unconvert(val), cs); + DataSegment.get(managerKey).update(key, MSGPACK.unconvert(val), cs); } catch (IOException e) { e.printStackTrace(); }
--- a/src/alice/daemon/OutboundTcpConnection.java Fri Jul 27 00:46:01 2012 +0900 +++ b/src/alice/daemon/OutboundTcpConnection.java Fri Jul 27 02:04:45 2012 +0900 @@ -10,6 +10,7 @@ public class OutboundTcpConnection extends Thread { public Connection connection; + private static MessagePack MSGPACK = new MessagePack(); public OutboundTcpConnection(Connection connection) { this.connection = connection; @@ -23,7 +24,6 @@ * pipeline thread for transmission */ public void run() { - MessagePack msgpack = new MessagePack(); while (true) { try { Command cmd = connection.sendQueue.take(); @@ -38,7 +38,7 @@ break; } CommandMessage cmdMsg = convert(cmd); - ByteBuffer buffer = ByteBuffer.wrap(msgpack.write(cmdMsg)); + ByteBuffer buffer = ByteBuffer.wrap(MSGPACK.write(cmdMsg)); while (buffer.hasRemaining()) { connection.socket.getChannel().write(buffer); }
--- a/src/alice/datasegment/Receiver.java Fri Jul 27 00:46:01 2012 +0900 +++ b/src/alice/datasegment/Receiver.java Fri Jul 27 02:04:45 2012 +0900 @@ -23,7 +23,7 @@ public String managerKey; // for debugging public String key; // for debugging - private static MessagePack msgpack = new MessagePack(); + private static MessagePack MSGPACK = new MessagePack(); public Receiver(InputDataSegment ids, CommandType type) { this.ids = ids; @@ -93,7 +93,7 @@ public <T> T asClass(Class<T> clazz) { try { - return msgpack.convert(val, clazz); + return MSGPACK.convert(val, clazz); } catch (IOException e) { e.printStackTrace(); }