简体   繁体   English

背景粘性并发标记扫描GC释放

[英]Background sticky concurrent mark sweep GC freed

I have an application that checks the database every 10 seconds if there is any new data, if there is any data it will get it and stop checking the database. 我有一个应用程序,如果有任何新数据,每10秒检查一次数据库,如果有任何数据,它将获得它并停止检查数据库。

I have implemented a text watcher to check if the textbox is empty. 我已经实现了一个文本观察器来检查文本框是否为空。 If it is, it will check the database, if it contains any text it will stop. 如果是,它将检查数据库,如果它包含将停止的任何文本。

This is my code: 这是我的代码:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    txtBoxUser.addTextChangedListener(checkUserRent);

    getData();
}


//TEXTWATCHER FOR GETTING PERSON WHO RENTED BOX
private final TextWatcher checkUserRent = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }
    public void afterTextChanged(Editable s) {
        if (s.length() == 0) {
            check();
        } else {
            Toast.makeText(MainActivity.this, "STOP",
                    Toast.LENGTH_LONG).show();
        }
    }
};


public void start(View view)
{
    getData();
}

public void cancel(View view)
{
    txtBoxUser.setText("");
    txtBoxPasscode.setText("");
}

private void getData(){

  final String id = txtBoxName.getText().toString().trim();

    class GetEmployee extends AsyncTask<Void,Void,String>{
        ProgressDialog loading;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
       //     loading = ProgressDialog.show(MainActivity.this,"Fetching...","Wait...",false,false);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
      //      loading.dismiss();
            showEmployee(s);
        }

        @Override
        protected String doInBackground(Void... params) {
            RequestHandler rh = new RequestHandler();
            String s = rh.sendGetRequestParam(DATA_URL,id);
            return s;
        }
    }
    GetEmployee ge = new GetEmployee();
    ge.execute();
}

private void showEmployee(String json){
    try {
        JSONObject jsonObject = new JSONObject(json);
        JSONArray result = jsonObject.getJSONArray(JSON_ARRAY);
        JSONObject c = result.getJSONObject(0);
        String name = c.getString(GET_BOXUSER);
        String desg = c.getString(GET_PASSCODE);

        txtBoxUser.setText(name);
        txtBoxPasscode.setText(desg);

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


private void check()
{
    getData();

}

But I get this in the logcat while it is waiting for the data. 但是我在logcat中等待数据时得到了这个。 I am just wondering is it okay or safe? 我只是想知道它还好还是安全?

I/art: Background sticky concurrent mark sweep GC freed 5614(449KB) AllocSpace objects, 18(288KB) LOS objects, 33% free, 1691KB/2MB, paused 5.354ms total 10.731ms
I/art: Background sticky concurrent mark sweep GC freed 7039(557KB) AllocSpace objects, 22(352KB) LOS objects, 39% free, 1561KB/2MB, paused 10.554ms total 15.931ms 
I/art: Background partial concurrent mark sweep GC freed 7279(564KB) AllocSpace objects, 21(336KB) LOS objects, 40% free, 1504KB/2MB, paused 5.721ms total 15.823ms
I/art: WaitForGcToComplete blocked for 5.375ms for cause HeapTrim
I/art: Background partial concurrent mark sweep GC freed 7650(591KB) AllocSpace objects, 22(352KB) LOS objects, 40% free, 1505KB/2MB, paused 5.511ms total 21.465ms

This is perfectly fine. 这很好。 It means that you're using memory, then its being freed by the GC. 这意味着你正在使用内存,然后被GC释放。 Its only a problem is either you go out of memory, or you see performance hiccups due to garbage collection. 它唯一的问题是要么你的内存不足,要么你看到由于垃圾收集导致的性能打嗝。 But its not anything you need to race to fix. 但它不是你需要竞争修复的任何东西。

I have had the same issue. 我有同样的问题。 Your code will work, but if this hangs for too long, the app can get a App Not Responding error and close. 您的代码将起作用,但如果此代码挂起太长时间,应用程序可能会收到App Not Responding错误并关闭。 It also defeats the purpose of using an AsyncTask. 它也违背了使用AsyncTask的目的。

The issue is that your AsyncTask contains a text view so it will block any other actions while executing. 问题是您的AsyncTask包含一个文本视图,因此它会在执行时阻止任何其他操作。 To fix this, make your AsyncTask static and pass it a reference to the Text view. 要解决此问题,请使AsyncTask保持静态,并将其传递给Text视图。 Then store it in a WeakReference. 然后将其存储在WeakReference中。

static class GetEmployee extends AsyncTask<Void,Void,String>{

    WeakReference<TextView> textUserWeakReference;
    WeakReference<TextView> textPassWeakReference;
    GetEmployee(TextView textUser, TextView textPass) {
        textUserWeakReference = new WeakReference<>(textUser);
        textPassWeakReference = new WeakReference<>(textPass);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
   //     loading = ProgressDialog.show(MainActivity.this,"Fetching...","Wait...",false,false);
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
  //      loading.dismiss();
        TextView textUser = textUserWeakReference.get();
        TextView textPass = textPassWeakReference.get();
        if(textView != null && textPass != null)
            showEmployee(s, textUser, textPass);
    }

    @Override
    protected String doInBackground(Void... params) {
        RequestHandler rh = new RequestHandler();
        String s = rh.sendGetRequestParam(DATA_URL,id);
        return s;
    }
}
private static void showEmployee(String json, TextView txtBoxUser, TextView txtBoxPassCode){
try {
    JSONObject jsonObject = new JSONObject(json);
    JSONArray result = jsonObject.getJSONArray(JSON_ARRAY);
    JSONObject c = result.getJSONObject(0);
    String name = c.getString(GET_BOXUSER);
    String desg = c.getString(GET_PASSCODE);

    txtBoxUser.setText(name);
    txtBoxPasscode.setText(desg);

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 改造 - 我/艺术:背景粘性并发标记扫描GC释放 - Retrofit - I/art: Background sticky concurrent mark sweep GC freed 使用 firebase 数据库时释放后台粘性并发标记扫描 GC - Background sticky concurrent mark sweep GC freed while using firebase database 后台粘性并发标记扫描 GC sqlite 数据库的无限循环 - infinite loop of Background sticky concurrent mark sweep GC sqlite database Android-处理大量XML数据-I / art:释放了后台部分并发标记清除GC - Android - Working with a lot of XML Data - I/art: Background partial concurrent mark sweep GC freed 获取 I/art:显式并发标记清除 GC 释放 - Getting I/art: Explicit concurrent mark sweep GC freed 陷入无限循环的日志:后台部分/粘性并发标记扫描 GC - Stuck in infinite loop with the log: Background partial/sticky concurrent mark sweep GC 我在日志中收到“背景粘性并发标记清除G”,然后什么也没有发生 - I get “Background sticky concurrent mark sweep G” in logs and then nothing happens Dalvik GC是否使用并发标记和清除或复制或同时使用? - Is Dalvik GC using concurrent mark and sweep or copying or both? 应用程序在“后台并发复制 GC 释放”日志消息后空闲时冻结 - App freezes when idle after "Background concurrent copying GC freed" log messages GC_CONCURRENT释放了1841K并杀死了我的MediaPlayer - GC_CONCURRENT freed 1841K and KILLED my MediaPlayer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM