I am using the latest Jetty websocket client and I have a simple client application to receive a video stream from a server. The stream is sent as a server push using approx 1 MB binary chunks. As the client socket I am just extending the Jetty's WebSocketAdapter class and the relevant part in my socket to receive the server push is:
@Override
public void onWebSocketBinary(final byte[] data, final int offset, final int length) {
dataCount += data.length;
}
As the client code is used for load testing, I am not processing the data any further, I am just expecting the data just being thrown away by the code. Also, to simulate several clients, I am creating several instances of WebSocketClient and the associated socket.
When running the clients, the java process memory usage is continuously increasing and eventually leads to an OutOfMemory situation. I tried to analyze heap dumps and I see the following:
So my question is, why the memory used by the byte arrays is not cleaned up? The memory consumption just keeps growing and growing without bounds. Is there anything I can do to clean up the arrays myself in my code?