LinwoodDev / Butterfly

🎨 Powerful, minimalistic, cross-platform, opensource note-taking app
https://butterfly.linwood.dev
GNU Affero General Public License v3.0
1.07k stars 77 forks source link

[Bug]: OutOfMemoryError: App crashes when attempting to load large note #761

Open maarriaa opened 3 days ago

maarriaa commented 3 days ago

What happened?

I have multiple notes in my Butterfly app. When I open the app, it takes quite a long time to load the list of all the notes and then open the selected note.

This time I was trying to open a bigger note - with multiple pages and many strokes on each of the pages but the app kept crashing (logs attached).

I have also often experienced the issue, where the app is lagging while creating a note with too many strokes as the one described here: https://github.com/LinwoodDev/Butterfly/issues/547

Version

2.2.1

Platform

Android

Relevant log output

--------- switch to main
11-18 18:37:22.349 10985 11038 D ProfileInstaller: Installing profile for dev.linwood.butterfly
11-18 18:38:11.761 10985 10985 I dev.linwood.butterfly: Waiting for a blocking GC Alloc
11-18 18:38:11.780 10985 10998 I dev.linwood.butterfly: Background concurrent mark compact GC freed 7101KB AllocSpace bytes, 21(1372KB) LOS objects, 42% free, 128MB/224MB, paused 231us,635us total 390.923ms
11-18 18:38:11.780 10985 10985 I dev.linwood.butterfly: WaitForGcToComplete blocked Alloc on Background for 19.126ms
11-18 18:38:11.780 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.093 10985 10998 I dev.linwood.butterfly: Clamp target GC heap from 348MB to 256MB
11-18 18:38:12.264 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.265 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.292 10985 10985 I dev.linwood.butterfly: Alloc concurrent mark compact GC freed 64KB AllocSpace bytes, 1(124MB) LOS objects, 42% free, 128MB/224MB, paused 74us,666us total 27.005ms
11-18 18:38:12.303 10985 10998 I dev.linwood.butterfly: Clamp target GC heap from 348MB to 256MB
11-18 18:38:12.739 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.739 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.749 10985 10985 I dev.linwood.butterfly: Clamp target GC heap from 348MB to 256MB
11-18 18:38:12.749 10985 10985 I dev.linwood.butterfly: Alloc concurrent mark compact GC freed 32KB AllocSpace bytes, 0(0B) LOS objects, 1% free, 252MB/256MB, paused 90us,345us total 9.909ms
11-18 18:38:12.750 10985 10985 I dev.linwood.butterfly: Forcing collection of SoftReferences for 249MB allocation
11-18 18:38:12.750 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.759 10985 10985 I dev.linwood.butterfly: Clamp target GC heap from 348MB to 256MB
11-18 18:38:12.759 10985 10985 I dev.linwood.butterfly: Alloc concurrent mark compact GC freed 232KB AllocSpace bytes, 0(0B) LOS objects, 1% free, 252MB/256MB, paused 56us,315us total 9.190ms
11-18 18:38:12.759 10985 10985 W dev.linwood.butterfly: Throwing OutOfMemoryError "Failed to allocate a 261808104 byte allocation with 3457920 free bytes and 3376KB until OOM, target footprint 268435456, growth limit 268435456" (VmSize 3475059112 kB)
11-18 18:38:12.759 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.759 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.768 10985 10985 I dev.linwood.butterfly: Clamp target GC heap from 348MB to 256MB
11-18 18:38:12.768 10985 10985 I dev.linwood.butterfly: Alloc concurrent mark compact GC freed 64KB AllocSpace bytes, 0(0B) LOS objects, 1% free, 252MB/256MB, paused 57us,307us total 9.107ms
11-18 18:38:12.768 10985 10985 I dev.linwood.butterfly: Forcing collection of SoftReferences for 249MB allocation
11-18 18:38:12.768 10985 10985 I dev.linwood.butterfly: Starting a blocking GC Alloc
11-18 18:38:12.777 10985 10985 I dev.linwood.butterfly: Clamp target GC heap from 348MB to 256MB
11-18 18:38:12.777 10985 10985 I dev.linwood.butterfly: Alloc concurrent mark compact GC freed 32KB AllocSpace bytes, 0(0B) LOS objects, 1% free, 252MB/256MB, paused 54us,306us total 8.886ms
11-18 18:38:12.778 10985 10985 W dev.linwood.butterfly: Throwing OutOfMemoryError "Failed to allocate a 261808104 byte allocation with 3457920 free bytes and 3376KB until OOM, target footprint 268435456, growth limit 268435456" (VmSize 3475059112 kB)
--------- switch to crash
11-18 18:38:12.778 10985 10985 E AndroidRuntime: FATAL EXCEPTION: main
11-18 18:38:12.778 10985 10985 E AndroidRuntime: Process: dev.linwood.butterfly, PID: 10985
11-18 18:38:12.778 10985 10985 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 261808104 byte allocation with 3457920 free bytes and 3376KB until OOM, target footprint 268435456, growth limit 268435456
11-18 18:38:12.778 10985 10985 E AndroidRuntime:    at java.util.Arrays.copyOf(Arrays.java:3585)
11-18 18:38:12.778 10985 10985 E AndroidRuntime:    at java.lang.AbstractStringBuilder.ensureCapacityInternal

java.lang.OutOfMemoryError: Failed to allocate a 261808040 byte allocation with 3457920 free bytes and 3376KB until OOM, target footprint 268435456, growth limit 268435456
    at java.util.Arrays.copyOf(Arrays.java:3585)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:177)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:753)
    at java.lang.StringBuilder.append(StringBuilder.java:257)
    at org.json.JSONTokener.nextString(JSONTokener.java:234)
    at org.json.JSONTokener.nextValue(JSONTokener.java:111)
    at org.json.JSONTokener.readObject(JSONTokener.java:403)
    at org.json.JSONTokener.nextValue(JSONTokener.java:104)
    at org.json.JSONTokener.readObject(JSONTokener.java:403)
    at org.json.JSONTokener.nextValue(JSONTokener.java:104)
    at org.json.JSONTokener.readArray(JSONTokener.java:449)
    at org.json.JSONTokener.nextValue(JSONTokener.java:107)
    at org.json.JSONTokener.readObject(JSONTokener.java:403)
    at org.json.JSONTokener.nextValue(JSONTokener.java:104)
    at org.json.JSONTokener.readObject(JSONTokener.java:403)
    at org.json.JSONTokener.nextValue(JSONTokener.java:104)
    at org.json.JSONTokener.readObject(JSONTokener.java:403)
    at org.json.JSONTokener.nextValue(JSONTokener.java:104)
    at V1.f.b(SourceFile:18)
    at V1.g.d(SourceFile:3)
    at V1.k$a.a(SourceFile:7)
    at N1.c.l(SourceFile:19)
    at N1.c.m(SourceFile:42)
    at N1.c.i(SourceFile:1)
    at N1.b.run(SourceFile:1)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8744)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ExecInit.main(ExecInit.java:50)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:369)

Code of Conduct

CodeDoctorDE commented 3 days ago

Hmm, out of memory errors are always tricky. And it happens after opening the file? How big is your file?

maarriaa commented 3 days ago

I clicked on the file and it started to load. The app crashed after a few seconds of loading. The file is 70MB