0

I'm getting a memory related crash in an Android app I'm making. This is where I've narrowed the crash down to:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("flow", "onCreate");
    setContentView(R.layout.activity_today);
    setGroup();
    mPager = (ViewPager) findViewById(R.id.today_activity_relative);
    mPagerAdapter = new MyAdaptor(getSupportFragmentManager());
    mPager.setAdapter(mPagerAdapter);
    PageChanger changer = new PageChanger();
    mPager.addOnPageChangeListener(changer);
    mPager.setCurrentItem(position);

    ImageView icon = new ImageView(this);
    icon.setImageResource(R.drawable.ic_action_new);
    FloatingActionButton actionButton = new FloatingActionButton.Builder(this).setContentView(icon).setBackgroundDrawable(R.drawable.action_button_selector).build();  //this is the culprit
    actionButton.setOnClickListener(this);
}

If I comment out the top two lines of the bottom group of code (and remove the setContentView method of the builder so it still runs), I still get the crash. But I comment out that one noted line (and the listener), it works fine.

This is the library I'm using to create the floating action button. The only modification I've made is calling my own drawable as seen in the code above, but I still get the crash when I use the default one in the library.

The crash occurs in a single activity, which contains a ViewPager that swipes between fragments that read from a database. The actual crash Logcat points to the database cursor as not having enough memory, and it occurs when swiping between pages often enough. The memory graph in AS slowly fills up to 16MB then the app unexpectedly quits. Whereas if I have the line in question commented out, I never go above 4-5MB.

I'm not asking anyone to debug this library for me, but I'd like get a better understanding of just what's going on here. It's very confusing to me. This is all taking place in onCreate, in an activity that never loses focus (and according to the logs this code only executes a single time).

Edit: Link to the Logcat and AS memory graphs screenshots.

Dan
  • 321
  • 3
  • 11
  • Hi., what happens if you put the logging below the setCOntentView.. Please show the logcat error too – Sheychan Jul 15 '15 at 01:56
  • I added a log statement along with the code in question, but it still only executes once. I've added a logcat screenshot and what the memory graph looks like for both crash and non crash to the question. – Dan Jul 15 '15 at 02:11
  • 1
    Check this out http://stackoverflow.com/questions/11340257/sqlite-android-database-cursor-window-allocation-of-2048-kb-failed – Sheychan Jul 15 '15 at 02:16
  • Maybe you should try to perform heap dump using Android Device Monitor and open the converted hprof file with Memory Analyzer (MAT) from Eclipse.org to pinpoint the leak. https://techblog.badoo.com/blog/2014/08/28/android-handler-memory-leaks – ecle Jul 15 '15 at 02:32
  • Thanks, Sheychan. Closing my cursors has fixed the problem. I didn't know that was necessary. It's still blowing my mind that having the floating action button disabled would prevent it crashing though. The two aren't related in any way, as far as I can tell. Mind boggling. – Dan Jul 18 '15 at 15:40

0 Answers0