Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

持续滑动会导致占用过多内存,然后崩溃 #1

Open
bqjhc opened this issue Jun 7, 2016 · 12 comments
Open

持续滑动会导致占用过多内存,然后崩溃 #1

bqjhc opened this issue Jun 7, 2016 · 12 comments
Assignees

Comments

@bqjhc
Copy link

bqjhc commented Jun 7, 2016

06-07 15:36:20.870 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for SecondFragment{8d91d5d #0 id=0x7f0d012e android:switcher:2131558702:1} not updated inline; expected state 3 found 2
06-07 15:36:30.935 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for ThirdFragment{f9d87d0 #2 id=0x7f0d012e android:switcher:2131558702:2} not updated inline; expected state 3 found 2
06-07 15:36:31.816 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for FourthFragment{1b1edef #3 id=0x7f0d012e android:switcher:2131558702:3} not updated inline; expected state 3 found 2
06-07 15:36:34.223 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for SecondFragment{8d91d5d #0 id=0x7f0d012e android:switcher:2131558702:1} not updated inline; expected state 3 found 2
06-07 15:36:34.490 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for FirstFragment{9fb7188 #1 id=0x7f0d012e android:switcher:2131558702:0} not updated inline; expected state 3 found 2
06-07 15:36:35.619 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for ThirdFragment{f9d87d0 #2 id=0x7f0d012e android:switcher:2131558702:2} not updated inline; expected state 3 found 2
06-07 15:36:36.393 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for FourthFragment{1b1edef #3 id=0x7f0d012e android:switcher:2131558702:3} not updated inline; expected state 3 found 2
06-07 15:36:37.204 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for SecondFragment{8d91d5d #0 id=0x7f0d012e android:switcher:2131558702:1} not updated inline; expected state 3 found 2
06-07 15:36:37.513 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for FirstFragment{9fb7188 #1 id=0x7f0d012e android:switcher:2131558702:0} not updated inline; expected state 3 found 2
06-07 15:36:40.484 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for ThirdFragment{f9d87d0 #2 id=0x7f0d012e android:switcher:2131558702:2} not updated inline; expected state 3 found 2
06-07 15:36:40.914 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for FourthFragment{1b1edef #3 id=0x7f0d012e android:switcher:2131558702:3} not updated inline; expected state 3 found 2
06-07 15:36:42.289 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for SecondFragment{8d91d5d #0 id=0x7f0d012e android:switcher:2131558702:1} not updated inline; expected state 3 found 2
06-07 15:36:42.787 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for FirstFragment{9fb7188 #1 id=0x7f0d012e android:switcher:2131558702:0} not updated inline; expected state 3 found 2
06-07 15:36:43.863 31470-31484/com.yingzhicheng.app.allchips I/art: Background sticky concurrent mark sweep GC freed 13697(7MB) AllocSpace objects, 2(40KB) LOS objects, 16% free, 39MB/47MB, paused 21.409ms total 144.588ms
06-07 15:36:43.887 31470-31482/com.yingzhicheng.app.allchips W/unknown:CloseableReference: Finalized without closing: c934d07 69a1e34 (type = CloseableStaticBitmap)
06-07 15:36:43.889 31470-31482/com.yingzhicheng.app.allchips W/unknown:CloseableReference: Finalized without closing: 50ae45d 425c1d2 (type = NativePooledByteBuffer)
06-07 15:36:44.865 31470-31470/com.yingzhicheng.app.allchips W/FragmentManager: moveToState: Fragment state for ThirdFragment{f9d87d0 #2 id=0x7f0d012e android:switcher:2131558702:2} not updated inline; expected state 3 found 2
06-07 15:36:45.081 31470-31480/com.yingzhicheng.app.allchips W/art: Suspending all threads took: 103.425ms
06-07 15:36:45.128 31470-31484/com.yingzhicheng.app.allchips I/art: Background sticky concurrent mark sweep GC freed 609(27KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 54MB/54MB, paused 37.584ms total 261.062ms
06-07 15:36:45.301 31470-31484/com.yingzhicheng.app.allchips I/art: Background partial concurrent mark sweep GC freed 27453(12MB) AllocSpace objects, 9(1252KB) LOS objects, 40% free, 40MB/67MB, paused 44.431ms total 173.269ms
06-07 15:36:45.311 31470-31482/com.yingzhicheng.app.allchips W/NativeMemoryChunk: finalize: Chunk 1f7998b still active. Underlying address = ffffffff9bac0000
06-07 15:36:46.068 31470-31470/com.yingzhicheng.app.allchips I/Choreographer: Skipped 71 frames! The application may be doing too much work on its main thread.
06-07 15:36:47.108 31470-31470/com.yingzhicheng.app.allchips D/AndroidRuntime: Shutting down VM

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 你的 Fragment,是一直在创建吗?

@CaMnter CaMnter self-assigned this Jun 7, 2016
@bqjhc
Copy link
Author

bqjhc commented Jun 7, 2016

我是按照你的例子写

@bqjhc
Copy link
Author

bqjhc commented Jun 7, 2016

代码也是直接复制过去的,oncreat方发里面调用initview,initdatas,这样

@bqjhc
Copy link
Author

bqjhc commented Jun 7, 2016

这个是我的activity文件

public class YingQiangActivity extends BaseActivity {

private RelativeLayout rl_back;
private SimpleDraweeView simpleDraweeView;
private EasySlidingTabs easySlidingTabs;
private ViewPager easyVP;
private TabsFragmentAdapter adapter;
List<Fragment> fragments;

public static final String[] titles = { "Any", "Bay", "Cue", "Dam" };
@Override
protected int getViewResid() {
    return R.layout.activity_ying_qiang;
}

@Override
protected void init() {
    rl_back = (RelativeLayout) findViewById(R.id.rl_back);
    rl_back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            YingQiangActivity.this.finish();
        }
    });
    simpleDraweeView = (SimpleDraweeView) findViewById(R.id.yingqiang_pic);
    easySlidingTabs = (EasySlidingTabs) findViewById(R.id.easy_sliding_tabs);
    easyVP = (ViewPager) findViewById(R.id.easy_vp);
    initCountDown();
}

@Override
protected void loadDatas() {
    Uri uri = Uri.parse("http://www.allchips.com/allin/images/ind_group_adv.jpg");
    simpleDraweeView.setImageURI(uri);
    fragments = new LinkedList<>();
    FirstFragment first = FirstFragment.getInstance();
    SecondFragment second = SecondFragment.getInstance();
    ThirdFragment third = ThirdFragment.getInstance();
    FourthFragment fourth = FourthFragment.getInstance();
    this.fragments.add(first);
    this.fragments.add(second);
    this.fragments.add(third);
    this.fragments.add(fourth);

    this.adapter = new TabsFragmentAdapter(this.getSupportFragmentManager(),titles,
            this.fragments);
    this.easyVP.setAdapter(this.adapter);
    this.easySlidingTabs.setViewPager(this.easyVP);
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}


@Override public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

这个是我的baseActivity
public abstract class BaseActivity extends AppCompatActivity{

private FragmentManager fragmentManager;
private Fragment showFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    fragmentManager=getSupportFragmentManager();
    Fresco.initialize(this);
    setContentView(getViewResid());
    ButterKnife.bind(this);
    init();
    loadDatas();
}

/**
 * 初始化方法,具体实现交给子类
 */
protected void init(){}

/**
 * 加载数据方法,具体实现交给子类
 */
protected void loadDatas(){}

/**
 * 返回需要显示的布局ID,该方法由子类实现
 * @return
 */
protected abstract int getViewResid();

/**
 * 带默认过程动画的启动Activity方式
 * @param intent
 */
@Override
public void startActivity(Intent intent) {
    this.startActivity(intent, R.anim.activity_in_left, R.anim.activity_out_down);
}
/**
 * 自定义Activity的过场动画
 * @param intent
 * @param animin
 * @param animout
 */
public void startActivity(Intent intent , int animin, int animout){
    super.startActivity(intent);
    overridePendingTransition(animin, animout);
}

/**
 * fragment管理——不包含过场动画的方式
 */
public void fragmentManager(int fl_resid, Class fclass){
    fragmentManager(fl_resid, 0, 0, fclass);
}
/**
 * 包含动画的fragment管理
 * @param fl_resid 给fragment占位的布局id
 * @param fclass  需要显示的fragment的Class对象
 * @param inanim  fragment进入的动画
 * @param outanim fragment退出的动画
 */
public void fragmentManager(int fl_resid, int inanim, int outanim, Class<BaseFragment> fclass){
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if(inanim != 0 || outanim != 0){
        fragmentTransaction.setCustomAnimations(inanim, outanim);
    }

    Fragment fragmentByTag = fragmentManager.findFragmentByTag(fclass.getName());
    if(showFragment != null){
        fragmentTransaction.hide(showFragment);
    }
    if(fragmentByTag != null){
        fragmentTransaction.show(fragmentByTag);
        showFragment = fragmentByTag;
    } else {
        BaseFragment baseFragment = BaseFragment.getInstance(fclass);
        System.out.print(fl_resid);
        System.out.print(baseFragment);
        System.out.print(fclass.getName());
        fragmentTransaction.add(fl_resid, baseFragment, fclass.getName());
        showFragment = baseFragment;
    }
    fragmentTransaction.commit();
}

}

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 我看看。

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 我这边看不出什么问题来,你可以换 TabLayout 试试。

查了一下相关问题:http://stackoverflow.com/questions/35810115/tabviewpager-not-updating-instead-shows-weird-warning-expected-state-3-found-2

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 你试试把

  1. YingQiangActivity 换成 AppCompatActivity,因为看到 BaseActivity 去了 FragmentManager,不知道做了什么。
  2. Fragment 换为 单例子。
  3. 以上,如果无法解决,换位 TabLayout 能解决的话,那么是我的问题。我会修复这个 bug。

目前无法断定是否是我的 bug。看到的日志都是 FragmentManager 的 log。

@bqjhc
Copy link
Author

bqjhc commented Jun 7, 2016

我尝试了不做修改,直接用你的例子运行也是同样的问题,频繁滑动后就崩溃了

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 我发现了,晚上会处理一下。

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 简单修改了一下,已经不会 OOM 。

CaMnter added a commit that referenced this issue Jun 7, 2016
CaMnter added a commit that referenced this issue Jun 7, 2016
@bqjhc
Copy link
Author

bqjhc commented Jun 7, 2016

额,Rebuild了一下,还是一样的情况

@CaMnter
Copy link
Owner

CaMnter commented Jun 7, 2016

@13652900200 我得重构一下代码,好久没看了,现在应该不会 OOM 。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants