A
A
ANasty2020-03-04 11:46:43
Java
ANasty, 2020-03-04 11:46:43

What causes the application to freeze when working with fragments?

Good afternoon. What we do: at the start of the activity, add a fragment

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        switch (c) {
            case (0):
                fragmentTransaction.add(R.id.frame, new Fragment1());
                break;
            case (1):
                fragmentTransaction.add(R.id.frame, new Fragment2());
                break;
            case (2):
                fragmentTransaction.add(R.id.frame, new Fragment3());
                break;
        }
        fragmentTransaction.commit();


Further, depending on the actions performed in the fragment, we replace it with a new fragment, etc.
public void getNextString() {
        int i = new Random().nextInt(3);
        while (resultsMassive[getNumString()][i+1] != null) {
            i = new Random().nextInt(3);
        }
        c = i;
    }

    public void replaceFragment() {
        if (variantsModelData.getTrainingList().size() > 0) {
            setResults();
            getNextString();
            variantsModelData.getTrainingList().remove(0);
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            switch (c) {
                case (0):
                    fragmentTransaction.replace(R.id.frame, new Fragment1());
                    break;
                case (1):
                    fragmentTransaction.replace(R.id.frame, new Fragment2());
                    break;
                case (2):
                    fragmentTransaction.replace(R.id.frame, new Fragment3());
                    break;
            }
            fragmentTransaction.commit();
        } else {
            resultsShow();
        }
    }

    private int getNumString() {
        for (int i = 0; i < resultsMassive.length; i++) {
            if (resultsMassive[i][0] == variantsModelData.getTrainingList().get(0).get(0)) {
                return i;
            }
        }
        return 0;
    }

    public void setResults() {
        resultsMassive[getNumString()][c + 1] = variantsModelData.isWin;
    }


At first everything goes ok, then at some point, when you click a button in a fragment (the click is processed and gives data to variantsModelData) and on this the application freezes with an unfinished button click animation and in the debugger the following

E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
I/chatty: uid=10525(com.xxx.yyy) HeapTaskDaemon identical 3 lines
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
D/: [ZeroHung]zrhung_send_event: wp=257, ret=-1
E/ZrHungImpl:  sendAppFreezeEvent failed!
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
I/chatty: uid=10525(com.xxx.yyy) HeapTaskDaemon identical 3 lines
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
I/chatty: uid=10525(com.xxx.yyy) HeapTaskDaemon identical 2 lines
E/: [ZeroHung]zrhung_get_config: Get config failed for wp[0x0008]
D/: [ZeroHung]zrhung_send_event: wp=258, ret=-1
E/ZrHungImpl:  sendAppFreezeEvent failed!


and beyond

Background concurrent copying GC freed 439209(8MB) AllocSpace objects, 0(0B) LOS objects, X% free, 7MB/14MB, paused 1.579ms total 119.148ms


where X is getting smaller each time

. I work with data of type List>, fragments get access to them through the ViewModel, in fragments I simply assign a reference to the object created in the activity. Freeze does not depend on the fragment, it can appear in any.

In the mode when I add one fragment and work with it, everything is ok, but if I change them all the time, I get this .. activate and freeze and happen before the fragment calls this method.

Unfortunately, it makes no sense to lay out the fragment codes, since it is too cumbersome and no one will understand what I wrote there anyway.

Question: Just tell me, please, what is the essence of the errors in the debugger? As far as I understand, this is not a memory leak, because the garbage collector is called and there is no OOM error.

UPD: I figured it out, overlooked it, and while in getNextString () looped endlessly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmtm, 2020-03-04
@Dmtm

add leakcanary to the project and everything will become clearer with memory leaks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question