GC_FOR_ALLOC释放了516K,9%免费9855K / 10759K

时间:2014-12-15 05:35:19

标签: java android garbage-collection

我的课程HandleJson有一个方法QuestionDone,如下所示:

public class HandleJSON {

    public AtomicBoolean QuestionDone(final String params) {
        final AtomicBoolean b = new AtomicBoolean(false);
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    String urlParameters = params; 
                    URL url = new URL("http://192.168.x.xx:xxxx/question_done");
                    HttpURLConnection conn = (HttpURLConnection) url
                            .openConnection();
                    conn.setReadTimeout(30000 /* milliseconds */);
                    conn.setConnectTimeout(50000 /* milliseconds */);
                    conn.setRequestMethod("GET");
                    // conn.setRequestProperty("User-Agent",
                    // "GYUserAgentAndroid");
                    conn.setRequestProperty("Content-Type", "application/json");
                    conn.setDoInput(true);
                    // conn.setUseCaches (false);
                    conn.setDoOutput(true);
                    DataOutputStream wr = new DataOutputStream(conn
                            .getOutputStream());
                    wr.writeBytes(urlParameters);
                    wr.flush();
                    wr.close();
                    // Starts the query
                    conn.connect();
                    System.out.println("Before url.openStream()");
                    InputStream stream = conn.getInputStream();// .openStream();
                    System.out.println("After url.openStream()");
                    String data = convertStreamToString(stream);
                    data = data.replace("\"", "").trim();
                    String temp = "";
                    temp = data.substring(0, data.indexOf(" "));
                    if (temp.equals("Thanks"))
                        b.set(true);
                    else
                        b.set(false);
                    readAndParseJSON(data);
                    stream.close();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        b.get();
        return b;
    }

}

我通过以下按钮从我的活动中调用此方法:

public class QuestionActivity extends ActionBarActivity implements
        GetQuestionAndAnswerList {

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question);


btn_parentDone = (Button) findViewById(R.id.btn_parentDone);
        btn_parentDone.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AtomicBoolean res;

                 concat_str = "abc";
                res = obj.QuestionDone(concat_str);
            }
        });
}
}

但我在error or exception行<{1}}下方res = obj.QuestionDone(concat_str);

12-15 09:49:25.486: D/dalvikvm(628): GC_FOR_ALLOC freed 516K, 9% free 9855K/10759K, paused 47ms, total 50ms

请建议我,我该如何解决这个问题。

等待回复。

由于

1 个答案:

答案 0 :(得分:0)

这不是错误,就是dalvik告诉你它回收堆内存。请参阅here