Home » Android » FATAL EXCEPTION: java.lang.OutOfMemoryError: EnsureLocalCapacity (FileInputStream.open0, android.graphics.Typeface.getFullFlipFont)

FATAL EXCEPTION: java.lang.OutOfMemoryError: EnsureLocalCapacity (FileInputStream.open0, android.graphics.Typeface.getFullFlipFont)

Posted by: admin May 14, 2020 Leave a comment

Questions:

After upgrading BuildTools from 23 to 27 I faced issue with crash.

I’ve checked RAM usage in profiler – there’s no anomaly there. App crashes sometimes in background, sometimes in foreground, in different activities (crash is completely nondeterministic), it doesn’t seem to depend on memory usage (was able to crash with 350mb usage like also with 200mb)

I also installed ‘square/leakcanary’ to find any memoryleaks, but nothing’s there…

Seems to be a problem with loading native typeface. I don’t use custom font in this application. I managed to crash app on Samsung S9 and Samsung S5. Any ideas? 🙁

Thanks for any help!

Stacktrace:

2018-10-05 08:09:04.740 20542-20542/pl.chillout.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: pl.chillout.debug, PID: 20542
java.lang.OutOfMemoryError: EnsureLocalCapacity
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:200)
    at java.io.FileInputStream.<init>(FileInputStream.java:150)
    at android.graphics.Typeface.getFullFlipFont(Typeface.java:1275)
    at android.graphics.Typeface.getFontPathFlipFont(Typeface.java:1220)
    at android.graphics.Typeface.SetFlipFonts(Typeface.java:1413)
    at android.graphics.Typeface.SetAppTypeFace(Typeface.java:1547)
    at android.app.Activity.onCreate(Activity.java:1020)
    at android.support.v4.app.SupportActivity.onCreate(SupportActivity.java:66)
    at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:321)
    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:84)
    at pl.chillout.redesign.activity.BaseDrawerActivity.onCreate(BaseDrawerActivity.java:45)
    at pl.chillout.redesign.activity.ChilloutActivity.onCreate(ChilloutActivity.java:115)
    at android.app.Activity.performCreate(Activity.java:7174)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
How to&Answers:

See if explicitly specifying default font in all your views fixes the issue. It looks like it’s trying to load a font that doesn’t exist.

 <TextView
  .....
 android:fontFamily="sans-serif" />

Answer:

the reason for this situation maybe you are using static objects like that :

private static TextView textView; //DO NOT DO THIS
private static Context context; //DO NOT DO THIS

this is the first sign of a memory leak.

Unfortunately there is no full code

Answer:

Dear add largeheap=true in manifest. then finish started activities. And check your drawable dimension (size). I faced this issue in PagerView. I resize drawable images. and finish all activity. and largheap now crash is removed. I think your error related to orio devices please initialize all objects for orio devices.

Answer:

Actually, I finally managed to fully “fix” this crash (as I mentioned in question comment section problem wasn’t applicable to release builds) by upgrading BuildTools from version 27 to 28.