gpt4 book ai didi

刷新数据时Android OutOfMemoryError

转载 作者:太空狗 更新时间:2023-10-29 12:54:20 26 4
gpt4 key购买 nike

在我的应用程序中,我每 3 分钟刷新一次数据。如果应用程序可以工作几个小时,我会遇到这样的错误:

java.lang.OutOfMemoryError
at org.apache.http.util.CharArrayBuffer.<init>(CharArrayBuffer.java:55)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:131)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:146)
at com.tab.Api.friends(Api.java:99)
at com.tab.TabLayout.updateFriends(TabLayout.java:692)
at com.tab.TabLayout.access$25(TabLayout.java:690)
at com.tab.TabLayout$7.run(TabLayout.java:684)
at java.lang.Thread.run(Thread.java:1102)

虽然我的代码在这个:“at com.tab.Api.friends(Api.java:99)” 地方看起来像这样:

    String result = "";
JSONObject jArray = null;
JSONArray friends = null;

DefaultHttpClient client = new DefaultHttpClient();
try
{
HttpGet getFriends = new HttpGet("http://##########"+fb);
HttpResponse getResponseFriends = client.execute(getFriends);
HttpEntity getFriendsEntity = getResponseFriends.getEntity();
if (getFriendsEntity != null)
result= EntityUtils.toString(getFriendsEntity);
try
{
jArray = new JSONObject(result);
}
catch(JSONException e)
{

}
}
catch(Exception e)
{
Log.d("LOADING ERROR","Friends section");
}

最佳答案

你的某处有内存泄漏。在某个地方,您持有对长期对象中内存密集型数据的引用。这样 GC 就无法收集这些数据。您的应用程序运行的时间越长,就会使用更多的内存,直到所有内存都用完。然后你的应用程序被 OutOfMemory Exception 杀死

可能对您有帮助的链接:

关于刷新数据时Android OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8444849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com