guardianproject / haven

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
https://guardianproject.github.io/haven/
GNU General Public License v3.0
6.63k stars 728 forks source link

OOM errors and ANRs #365

Closed archie94 closed 5 years ago

archie94 commented 5 years ago

Getting OOM errors on the current dev branch (272b3416c8812b9c79dad3994acca26af9d57111)

Logs:

java.lang.OutOfMemoryError: Failed to allocate a 8294412 byte allocation with 1663176 free bytes and 1624KB until OOM
 at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
 at android.graphics.Bitmap.nativeCreate(Native Method)
 at android.graphics.Bitmap.createBitmap(Bitmap.java:890)
 at android.graphics.Bitmap.createBitmap(Bitmap.java:867)
 at android.graphics.Bitmap.createBitmap(Bitmap.java:798)
 at org.havenapp.main.sensors.motion.MotionDetector.detect(MotionDetector.java:132)
 at org.havenapp.main.sensors.motion.CameraViewHolder.processNewFrame(CameraViewHolder.java:330)
 at org.havenapp.main.sensors.motion.CameraViewHolder.access$700(CameraViewHolder.java:57)
 at org.havenapp.main.sensors.motion.CameraViewHolder$2.lambda$process$0(CameraViewHolder.java:234)
 at org.havenapp.main.sensors.motion.-$$Lambda$CameraViewHolder$2$B8P48X5F17tkzOvmZzEKi2v1Qac.run(lambda)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
 at java.lang.Thread.run(Thread.java:760)
java.lang.OutOfMemoryError: Failed to allocate a 8294412 byte allocation with 2870720 free bytes and 2MB until OOM
 at org.havenapp.main.sensors.media.ImageCodec.lumaToGreyscale(ImageCodec.java:44)
 at org.havenapp.main.sensors.media.ImageCodec.lumaToBitmapGreyscale(ImageCodec.java:55)
 at org.havenapp.main.sensors.motion.MotionDetector.detect(MotionDetector.java:111)
 at org.havenapp.main.sensors.motion.CameraViewHolder.processNewFrame(CameraViewHolder.java:330)
 at org.havenapp.main.sensors.motion.CameraViewHolder.access$700(CameraViewHolder.java:57)
 at org.havenapp.main.sensors.motion.CameraViewHolder$2.lambda$process$0(CameraViewHolder.java:234)
 at org.havenapp.main.sensors.motion.-$$Lambda$CameraViewHolder$2$B8P48X5F17tkzOvmZzEKi2v1Qac.run(lambda)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
 at java.lang.Thread.run(Thread.java:760)

These are reproducible on my side when you reduce the motion detection sensitivity significantly. Furthermore on deactivating an ongoing Event session there are frame skips which are areas that needs optimizations.

2019-02-07 23:54:27.380 7795-7795/org.havenapp.main I/CameraFragment: SERVICE DISCONNECTED
2019-02-07 23:54:27.633 7795-7844/org.havenapp.main D/Camera: app passed NULL surface
2019-02-07 23:54:27.844 7795-8151/org.havenapp.main D/skia: onFlyCompress
2019-02-07 23:54:27.852 7795-7806/org.havenapp.main I/art: Background sticky concurrent mark sweep GC freed 22(26KB) AllocSpace objects, 2(56KB) LOS objects, 0% free, 86MB/86MB, paused 772us total 103.571ms
2019-02-07 23:54:31.781 7795-7844/org.havenapp.main D/Camera: app passed NULL surface
2019-02-07 23:54:31.792 7795-7795/org.havenapp.main I/Choreographer: Skipped 248 frames!  The application may be doing too much work on its main thread.
2019-02-07 23:54:33.778 7795-7800/org.havenapp.main I/art: Do full code cache collection, code=104KB, data=125KB
2019-02-07 23:54:33.779 7795-7800/org.havenapp.main I/art: After code cache collection, code=103KB, data=100KB

Device Info: Redmi Note 4(mido) MIUI Global 10.1 Android version 7.0

n8fr8 commented 5 years ago

This is the flip side of not using RenderScript to handle some of the bitmap conversion.... will dig in!

n8fr8 commented 5 years ago

How much RAM does your device have?

n8fr8 commented 5 years ago

Ah, 4GB! Hmm. https://www.gsmarena.com/xiaomi_redmi_note_4-8531.php

n8fr8 commented 5 years ago

The issue is that your camera is very high res compared to my devices. This can be fixed by controlling resolution of the new CameraView.