Maybe my doubt is a bit silly. But I couldn’t find any answer similar with my problem. But after some time requests (about 20 invocations of this method), the client get a java.lang.OutOfMemoryError: Java heap space
the client is:
final ClientResource cr = new ClientResource(host + userInteracId);
try {
Client httpClient = new Client(Protocol.HTTP);
httpClient.setConnectTimeout(36000);
cr.setNext(httpClient);
JSONObject obj = new JSONObject();
JsonRepresentation jr = new JsonRepresentation(obj);
cr.put(jr);
jr.release();
cr.setNext(httpClient);
Representation r = cr.get();
result = new JsonRepresentation(r).getJsonObject();
r.release();
} catch (Exception e) {
result = new JSONObject();
} finally {
cr.release();
cr.getResponseEntity().release();
}
and the Exception is:
WARNING: Unexpected error while controlling connector
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:39)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:312)
at org.restlet.engine.io.Buffer.createByteBuffer(Buffer.java:64)
at org.restlet.engine.io.Buffer.<init>(Buffer.java:125)
at org.restlet.engine.connector.Way.<init>(Way.java:97)
at org.restlet.engine.connector.OutboundWay.<init>(OutboundWay.java:105)
at org.restlet.engine.connector.ClientOutboundWay.<init>(ClientOutboundWay.java:59)
at org.restlet.engine.connector.HttpClientOutboundWay.<init>(HttpClientOutboundWay.java:59)
at org.restlet.engine.connector.HttpClientHelper.createOutboundWay(HttpClientHelper.java:63)
at org.restlet.engine.connector.Connection.<init>(Connection.java:128)
…
If an exception is raised before the jr.release() or the r.release(), those methods will never get called. The only release() called in the finally block is for cr, not jr or r.
I recommend putting some logging in the catch block to see if an exception is being thrown.