restlet客户端中的Java堆溢出

restlet客户端中的Java堆溢出,java,restlet,heap-memory,Java,Restlet,Heap Memory,也许我的怀疑有点傻。但我找不到与我的问题类似的答案。但是经过一段时间的请求(大约20次调用此方法)后,客户机会得到一个java.lang.OutOfMemoryError:java堆空间 客户是: final ClientResource cr = new ClientResource(host + userInteracId); try { Client httpClient = new Client(Protocol.HTTP); httpClient.setConnectT

也许我的怀疑有点傻。但我找不到与我的问题类似的答案。但是经过一段时间的请求(大约20次调用此方法)后,客户机会得到一个java.lang.OutOfMemoryError:java堆空间

客户是:

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();
}
例外情况是:

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)
警告:控制连接器时出现意外错误
java.lang.OutOfMemoryError:java堆空间
位于java.nio.HeapByteBuffer。(HeapByteBuffer.java:39)
位于java.nio.ByteBuffer.allocate(ByteBuffer.java:312)
位于org.restlet.engine.io.Buffer.createByteBuffer(Buffer.java:64)
位于org.restlet.engine.io.Buffer(Buffer.java:125)
位于org.restlet.engine.connector.Way.(Way.java:97)
位于org.restlet.engine.connector.OutboundWay(OutboundWay.java:105)
位于org.restlet.engine.connector.ClientOutboundWay(ClientOutboundWay.java:59)
位于org.restlet.engine.connector.HttpClientOutboundWay。(HttpClientOutboundWay.java:59)
位于org.restlet.engine.connector.HttpClientHelper.createOutboundWay(HttpClientHelper.java:63)
位于org.restlet.engine.connector.Connection.(Connection.java:128)

如果在jr.release()或r.release()之前引发异常,则永远不会调用这些方法。在finally块中调用的惟一release()用于cr,而不是jr或r


我建议在catch块中放置一些日志记录,以查看是否抛出异常。

您必须释放此代码返回的结果吗?我将尝试Eclipse内存分析器,观察堆并查看堆中填充的是什么类型的类。