android volley 超时,android – Volley缓慢而导致内存泄漏
在我的項目中,我使用volley來下載一個JSON流,我將其解析并顯示在列表視圖中.我使用以下方法加載我的數據:
private void loadEventData(int year, final int month) {
// get volley request queue
requestQueue = cpcApplication.getRequestQueue(getActivity());
String url = "****************?year=" + year
+ "&month=" + month;
pd = ProgressDialog.show(getActivity(), "Loading Events", "Retrieving Data from Server");
pd.setCancelable(true);
JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, response.toString());
// parse the incoming response
parseJson(response, month);
// notify the listview that the data set has changed
adapter.notifyDataSetChanged();
// set the listview at the top position
listView.setSelection(current.get(Calendar.DAY_OF_MONTH));
// dismiss the ProgressDialog
pd.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
// cancel the progress dialog
pd.dismiss();
// let the user know that a network connection is not available
Toast.makeText(getActivity(), "Cannot communicate with server. Check network connection.", Toast.LENGTH_LONG).show();
}
});
// add the network request to the queue
requestQueue.add(jr);
}
對此方法的第一次調用非常有效.在第二次調用中,我收到超時錯誤.當我使用以下命令時:
jr.setRetryPolicy(new DefaultRetryPolicy(
2500, DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
為了增加請求的時間,請求超過30秒并產生以下日志輸出:
10-19 20:53:19.746: D/Volley(17523): [2786] BasicNetwork.logSlowRequests: HTTP response for request= [lifetime=41769], [size=5467846], [rc=200], [retryCount=2]
10-19 20:53:19.796: D/dalvikvm(17523): GC_CONCURRENT freed 7462K, 26% free 24424K/33000K, paused 6ms+4ms, total 56ms
10-19 20:53:19.796: D/dalvikvm(17523): WAIT_FOR_CONCURRENT_GC blocked 51ms
10-19 20:53:19.826: I/dalvikvm-heap(17523): Grow heap (frag case) to 35.123MB for 10935708-byte allocation
10-19 20:53:19.857: D/dalvikvm(17523): GC_FOR_ALLOC freed 3K, 20% free 35100K/43680K, paused 23ms, total 28ms
10-19 20:53:19.917: D/dalvikvm(17523): GC_CONCURRENT freed 2018K, 19% free 35816K/43680K, paused 3ms+4ms, total 60ms
10-19 20:53:20.007: D/dalvikvm(17523): GC_CONCURRENT freed 4874K, 15% free 37226K/43680K, paused 2ms+3ms, total 27ms
10-19 20:53:20.007: D/dalvikvm(17523): WAIT_FOR_CONCURRENT_GC blocked 24ms
10-19 20:53:20.067: D/dalvikvm(17523): GC_FOR_ALLOC freed 5037K, 15% free 38601K/44900K, paused 19ms, total 19ms
10-19 20:53:20.117: D/dalvikvm(17523): GC_FOR_ALLOC freed 4680K, 14% free 40045K/46564K, paused 20ms, total 20ms
10-19 20:53:20.177: D/dalvikvm(17523): GC_FOR_ALLOC freed 5576K, 14% free 41572K/48272K, paused 20ms, total 20ms
10-19 20:53:20.227: D/dalvikvm(17523): GC_FOR_ALLOC freed 6133K, 15% free 43406K/50548K, paused 20ms, total 20ms
10-19 20:53:20.287: D/dalvikvm(17523): GC_CONCURRENT freed 6486K, 15% free 45029K/52428K, paused 2ms+2ms, total 24ms
10-19 20:53:20.287: D/dalvikvm(17523): WAIT_FOR_CONCURRENT_GC blocked 11ms
10-19 20:53:20.407: D/Volley(17523): [1] Request.finish: 42553 ms: [ ] http://****** 0x63ea5535 NORMAL 1
當我在瀏覽器中執行相同的請求時,只需幾秒鐘.為什么延遲和令人難以置信的內存消耗?
總結
以上是生活随笔為你收集整理的android volley 超时,android – Volley缓慢而导致内存泄漏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux任督二脉之内存管理(二) PP
- 下一篇: POI和easyExcel使用(2)Po