多くの http リクエスト (HttpURLConnection) を送信するアンドロイ アプリを開発しています。すべてが機能していますが、オブジェクトが解放されていないと思います。MAT (Eclipse Memory Analyzer) を見ると、多くの byte[] が保持されていると表示されるためです。MAT のバイトを調べると、HttpURLConnection メソッドで受け取ったバイトです。以下は、http リクエストを送信するための私のコードです。オブジェクトを解放するために他にできることはありますか?
public static String sendHTTPRequest(String requestURL, int timeout) {
HttpURLConnection httpconn = null;
try {
URI uri = new URI(getUTF8Request(requestURL));
httpconn = (HttpURLConnection) uri.toURL().openConnection();
httpconn.setConnectTimeout(timeout);
StringBuilder responseStringBuilder = new StringBuilder();
if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader input = new BufferedReader(
new InputStreamReader(httpconn.getInputStream(),
"ISO-8859-1"), 8192);
String strLine = null;
while ((strLine = input.readLine()) != null) {
responseStringBuilder.append(strLine);
}
input.close();
strLine = null;
input = null;
}
return responseStringBuilder.toString();
} catch (URISyntaxException e) {
httpconn = null;
return "Failed to request";
} catch (IOException e) {
httpconn = null;
return "Failed to request";
} finally {
requestURL = null;
if (httpconn != null) {
httpconn.disconnect();
httpconn = null;
}
}
}