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

OOM: Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 1101856 free bytes and 1076KB until OOM, target footprint 201326592, growth limit 201326592; failed due to fragmentation (largest possible contiguous allocation 32768000 bytes) #500

Closed
AhmadAyyaz1993 opened this issue Oct 12, 2023 · 2 comments

Comments

@AhmadAyyaz1993
Copy link

Library information:

  • Version: 1.0.4

Describe the bug**

On some old low end devices running some older version of android like android 8, it is throwing out of memory exception whenever we try to load the calendar and the crash is occurring on the method call updateMonthConfiguration and in this method when we try to set inDateStyle = InDateStyle.ALL_MONTHS. The complete code block is this:

calendarView.updateMonthConfiguration(
               inDateStyle = InDateStyle.ALL_MONTHS, //This is the line where exception is being thrown
               maxRowCount = 6,
               hasBoundaries = true,
       )

So we have also tried to migrate to 2.x.x version of the library but we are still getting issues because the 2.x.x version of the library is built using JDK 17 but our project is built on JDK 11. So any help would be highly appreciated, if you can suggest us some workaround.

To Reproduce (if applicable)

Steps to reproduce the behavior:
Simply when trying to load calendar view.

Expected behavior (if applicable)

It should not throw OOM exception. It should operate major operations on the background thread.

Additional information

Here is the complete stacktrace:
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 1101856 free bytes and 1076KB until OOM, target footprint 201326592, growth limit 201326592; failed due to fragmentation (largest possible contiguous allocation 32768000 bytes) at j$.time.LocalDate.G(:112) at j$.time.LocalDate.of(:18) at com.kizitonwose.calendarview.model.MonthConfig$Companion.generateWeekDays$com_github_kizitonwose_CalendarView(MonthConfig.java:188) at com.kizitonwose.calendarview.model.MonthConfig$Companion.generateBoundedMonths(MonthConfig.java:57) at com.kizitonwose.calendarview.model.MonthConfig.<init>(MonthConfig.java:23) at com.kizitonwose.calendarview.CalendarView.updateAdapterMonthConfig(CalendarView.java:419) at com.kizitonwose.calendarview.CalendarView.updateAdapterMonthConfig$default(CalendarView.java:416) at com.kizitonwose.calendarview.CalendarView.updateMonthConfiguration(CalendarView.java:451) at com.kizitonwose.calendarview.CalendarView.updateMonthConfiguration$default(CalendarView.java:442) at com.tracer.joblogic.jobs.utils.customDateTimePicker.DateFragment.onCreateView(DateFragment.java:88) at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100) at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1971) at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:311) at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:249) at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244) at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092) at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622) at android.view.View.measure(View.java:27137) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552) at android.widget.LinearLayout.measureVertical(LinearLayout.java:842) at android.widget.LinearLayout.onMeasure(LinearLayout.java:721) at android.view.View.measure(View.java:27137) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:27137) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:27137) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:1218) at android.view.View.measure(View.java:27137) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:4257) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2960) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3259) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2669) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10092) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1010) at android.view.Choreographer.doCallbacks(Choreographer.java:809) at android.view.Choreographer.doFrame(Choreographer.java:744) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:995) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:247) at android.app.ActivityThread.main(ActivityThread.java:8676) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

@kizitonwose
Copy link
Owner

kizitonwose commented Nov 5, 2023

Hi, in version 1.x.x, the needed months were generated in memory which can cause issues on low-end devices if you want to show a really large date range. Since version 2, this has been optimized to be generated as needed.

However, I see that you cannot update to version 2 due to JDK version issues so I am not sure what the best action would be for you.

I am concerned about why you cannot upgrade to JDK 17. For example, in the sample project included with this repo, I was able to change the source/target compatibility to Java 11 and the project runs fine even though the libraries are still set to Java 17.

Edit: If you meant the build JDK itself not the one set for source/target compatibility, then I cannot really get the same environment in the sample project as downgrading the build JDK would involve downgrading the AGP version which will definitely raise more build issues. This seems like jumping through multiple hoops for an issue that already has a better fix.

@kizitonwose
Copy link
Owner

I will close this issue since I do not have the resources to provide support for very old library versions. Let's put all the effort in the other thread to see if the JDK issue can be resolved as more people will benefit from that.

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