Skip to content

Commit 9c22889

Browse files
author
Zhen Li
authored
Merge pull request #207 from zhenlineo/1.0-memory-leak
Reduce long time memory usage
2 parents 541cd55 + 63bf292 commit 9c22889

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

driver/src/main/java/org/neo4j/driver/internal/connector/socket/BufferingChunkedInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public BufferingChunkedInput( ReadableByteChannel ch )
8181
public BufferingChunkedInput( ReadableByteChannel channel, int bufferCapacity )
8282
{
8383
assert bufferCapacity >= 1;
84-
this.buffer = ByteBuffer.allocateDirect( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
84+
this.buffer = ByteBuffer.allocate( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
8585
this.buffer.limit( 0 );
86-
this.scratchBuffer = ByteBuffer.allocateDirect( 8 ).order( ByteOrder.BIG_ENDIAN );
86+
this.scratchBuffer = ByteBuffer.allocate( 8 ).order( ByteOrder.BIG_ENDIAN );
8787
this.channel = channel;
8888
this.state = State.AWAITING_CHUNK;
8989
}

driver/src/main/java/org/neo4j/driver/internal/connector/socket/ChunkedInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ChunkedInput implements PackInput
3737
private final ByteBuffer buffer;
3838

3939
/* a special buffer for chunk header */
40-
private final ByteBuffer chunkHeaderBuffer = ByteBuffer.allocateDirect( 2 );
40+
private final ByteBuffer chunkHeaderBuffer = ByteBuffer.allocate( 2 );
4141

4242
/* the size of bytes that have not been read in current incoming chunk */
4343
private int unreadChunkSize = 0;
@@ -52,7 +52,7 @@ public ChunkedInput( ReadableByteChannel ch )
5252
public ChunkedInput( int bufferCapacity, ReadableByteChannel channel )
5353
{
5454
assert bufferCapacity >= 1;
55-
buffer = ByteBuffer.allocateDirect( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
55+
buffer = ByteBuffer.allocate( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
5656
buffer.limit( 0 );
5757
this.channel = channel;
5858
}

driver/src/main/java/org/neo4j/driver/internal/connector/socket/ChunkedOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ChunkedOutput( WritableByteChannel ch )
4848

4949
public ChunkedOutput( int bufferSize, WritableByteChannel ch )
5050
{
51-
buffer = ByteBuffer.allocateDirect( max( 16, bufferSize ) );
51+
buffer = ByteBuffer.allocate( max( 16, bufferSize ) );
5252
chunkOpen = false;
5353
channel = ch;
5454
}

driver/src/main/java/org/neo4j/driver/internal/connector/socket/SocketClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private SocketProtocol negotiateProtocol() throws IOException
170170
{
171171
logger.debug( "~~ [HANDSHAKE] [0x6060B017, 1, 0, 0, 0]." );
172172
//Propose protocol versions
173-
ByteBuffer buf = ByteBuffer.allocateDirect( 5 * 4 ).order( BIG_ENDIAN );
173+
ByteBuffer buf = ByteBuffer.allocate( 5 * 4 ).order( BIG_ENDIAN );
174174
buf.putInt( MAGIC_PREAMBLE );
175175
for ( int version : SUPPORTED_VERSIONS )
176176
{

driver/src/main/java/org/neo4j/driver/internal/connector/socket/TLSSocketChannel.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class TLSSocketChannel implements ByteChannel
6161
private ByteBuffer plainIn;
6262
private ByteBuffer plainOut;
6363

64-
private static final ByteBuffer DUMMY_BUFFER = ByteBuffer.allocateDirect( 0 );
64+
private static final ByteBuffer DUMMY_BUFFER = ByteBuffer.allocate( 0 );
6565

6666
public TLSSocketChannel( String host, int port, ByteChannel channel, Logger logger,
6767
TrustStrategy trustStrategy )
@@ -75,10 +75,10 @@ public TLSSocketChannel( String host, int port, ByteChannel channel, Logger logg
7575
public TLSSocketChannel( ByteChannel channel, Logger logger, SSLEngine sslEngine ) throws GeneralSecurityException, IOException
7676
{
7777
this(channel, logger, sslEngine,
78-
ByteBuffer.allocateDirect( sslEngine.getSession().getApplicationBufferSize() ),
79-
ByteBuffer.allocateDirect( sslEngine.getSession().getPacketBufferSize() ),
80-
ByteBuffer.allocateDirect( sslEngine.getSession().getApplicationBufferSize() ),
81-
ByteBuffer.allocateDirect( sslEngine.getSession().getPacketBufferSize() ) );
78+
ByteBuffer.allocate( sslEngine.getSession().getApplicationBufferSize() ),
79+
ByteBuffer.allocate( sslEngine.getSession().getPacketBufferSize() ),
80+
ByteBuffer.allocate( sslEngine.getSession().getApplicationBufferSize() ),
81+
ByteBuffer.allocate( sslEngine.getSession().getPacketBufferSize() ) );
8282
}
8383

8484
TLSSocketChannel( ByteChannel channel, Logger logger, SSLEngine sslEngine,
@@ -216,7 +216,7 @@ private HandshakeStatus unwrap( ByteBuffer buffer ) throws IOException
216216
"buffer size allowed is %s. The content in the buffer is: %s\n",
217217
curAppSize, newAppSize, appSize * 2, BytePrinter.hex( plainIn ) ) );
218218
}
219-
ByteBuffer newPlainIn = ByteBuffer.allocateDirect( newAppSize );
219+
ByteBuffer newPlainIn = ByteBuffer.allocate( newAppSize );
220220
newPlainIn.put( plainIn );
221221
plainIn = newPlainIn;
222222
logger.debug( "Enlarged application input buffer from %s to %s. " +
@@ -229,7 +229,7 @@ private HandshakeStatus unwrap( ByteBuffer buffer ) throws IOException
229229
// Resize buffer if needed.
230230
if ( netSize > curNetSize )
231231
{
232-
ByteBuffer newCipherIn = ByteBuffer.allocateDirect( netSize );
232+
ByteBuffer newCipherIn = ByteBuffer.allocate( netSize );
233233
newCipherIn.put( cipherIn );
234234
cipherIn = newCipherIn;
235235
logger.debug( "Enlarged network input buffer from %s to %s. " +
@@ -297,7 +297,7 @@ private HandshakeStatus wrap( ByteBuffer buffer ) throws IOException
297297
"new network buffer.", curNetSize, netSize, buffer.capacity() ) );
298298
}
299299

300-
cipherOut = ByteBuffer.allocateDirect( netSize );
300+
cipherOut = ByteBuffer.allocate( netSize );
301301
logger.debug( "Enlarged network output buffer from %s to %s. " +
302302
"This operation should be a rare operation.", curNetSize, netSize );
303303
break;

driver/src/main/java/org/neo4j/driver/internal/packstream/BufferedChannelInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public BufferedChannelInput(ReadableByteChannel ch )
3939

4040
public BufferedChannelInput( int bufferCapacity, ReadableByteChannel ch )
4141
{
42-
this.buffer = ByteBuffer.allocateDirect( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
42+
this.buffer = ByteBuffer.allocate( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
4343
reset( ch );
4444
}
4545

driver/src/main/java/org/neo4j/driver/internal/packstream/BufferedChannelOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class BufferedChannelOutput implements PackOutput
3030

3131
public BufferedChannelOutput( int bufferSize )
3232
{
33-
this.buffer = ByteBuffer.allocateDirect( bufferSize ).order( ByteOrder.BIG_ENDIAN );
33+
this.buffer = ByteBuffer.allocate( bufferSize ).order( ByteOrder.BIG_ENDIAN );
3434
}
3535

3636
public BufferedChannelOutput( WritableByteChannel channel )

0 commit comments

Comments
 (0)