mvysny / photocloud-frame-slideshow

Android Digital Photo Frame
https://www.android-photo-frame.eu
15 stars 1 forks source link

OutOfMemoryError #81

Closed jankete closed 6 years ago

jankete commented 6 years ago

I used to get some OutOfMemoryError after running the app for some time. I have seen this issue https://github.com/mvysny/photocloud-frame-slideshow/issues/53, but all my images are as job in a single folder and only have full HD resolution (as my screen has). So they are small in filesize and should not cause any memory problems. screenshot_20180305-155018 screenshot_20180305-155049

mvysny commented 6 years ago

Hmm. Could it be that the memory is so fragmented by the app running for the long time that there is not enough continuous space? That doesn't make much sense. Perhaps there is some hidden memory leak? Let me look at the code.

jankete commented 6 years ago

Don't know. I only use the the tablet for this slideshow. There are no other apps running. Maybe you find something in the code.

mvysny commented 6 years ago

Hmm, just received a bug report which reinforces the fragmentation issue. I'll try to investigate whether I can do some simple steps to optimize in this area as well.

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 94 byte allocation with 16777216 free bytes and 372MB until OOM; failed due to fragmentation (required continguous free 8192 bytes for a new buffer where largest contiguous free 4096 bytes)
       at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
       at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:146)
       at java.lang.StringBuilder.append(StringBuilder.java:216)
       at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
       at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
       at sk.baka.photoframe.Config.<init>(Config.kt:21)
mvysny commented 6 years ago

Do you perhaps happen to run Android 5, perhaps on a Samsung device?

A fellow Android developer writes:

So the app tried to allocate 94 bytes out of the 1613776 free bytes that it had, but failed due to fragmentation, it could not find 8192 free continguous bytes for a new buffer.

This article explains that it is because the OS has poor ram management. I've seen this issue happening in my app on phones with Android 5 and 6, and I don't think that as developers we can do something to fix it.

So any long-running Android app is poised to crash sooner or later. Brilliant. I've lost any ideals of Android that I've had - it's really a steaming pile of shit.

jankete commented 6 years ago

It is a Samsung device (Galaxy Tab A), but it runs on Android 7.1.2 (LineageOS 14.1) .

What I do is: I start the app on usb-power which is activated by motion detection via philipy hue a osram power switch. So when I enter the living room the slideshow starts. When no motion is detected for 30 minutes the power is switched off and the slideshow ends. So I think it runs no longer than for some hours. Sometime I get the memory error after a while, sometimes after the first few pictures and sometimes it doesn't occur.

mvysny commented 6 years ago

Could it be perhaps related to a picture which is corrupted in the filesystem? Would it be reasonable to try to find such a photo, or do you have thousands of photos?

jankete commented 6 years ago

Currently I have 113 pictures on the source folder (dropbox). I reviewed all of them an all seem to be ok.

mvysny commented 6 years ago

Then it is probably the case of crappy Android memory management. More info here: https://groups.google.com/forum/#!topic/android-developers/pam6BSKeRIM I'll try to call System.gc() periodically, maybe it will help.

mvysny commented 6 years ago

Blind-fixed in 1.11.3, please reopen if you'll still get the OutOfMemoryError even with PhotoCloud 1.11.3.