我正在开发一个发送大量 http 请求(HttpURLConnection)的安卓应用程序。一切正常,但我认为我的对象没有被释放。我这么说是因为当我查看 MAT(Eclipse 内存分析器)时,它说我保留了很多字节 []。我查看了 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;
}
}
}