According to the documentation https://developer.android.com/topic/performance/graphics/manage-memory starting with Android 8.0 Bitmaps are again stored in the native memory instead of Dalvik heap. But doesn't it return all the problems that have existed before Android 3 when Bitmap were stored in the native memory as well? Specifically, from my understanding, as Bitmaps are stored in the native memory again, there can be out of memory issues since large bitmaps do not create memory pressure for GC. Do I understand it wrongly?
- OuOfMemory issues can happen either way. Storing it in Dalvik memory doesn't reduce total memory usage by any meaningful amount, but can have negative effects on the garbage collection algorithm. I'd trust the OS developers to have measured both and made the right choice. The memory issue frequency back in the day wasn't due to having it in native memory, it was due to the devices having tiny amounts of RAM. Bigger RAM and more aggressive killing of background apps is why you don't seill see them.Gabe Sechan– Gabe Sechan2024-08-12 05:05:30 +00:00Commented Aug 12, 2024 at 5:05
- The real reason to choose dalvik or native memory has to do with how having large allocations effects the gc. I can see having those large allocations causing unnecessary framentation of the memory pool and causing OOM issues due to that when allocating other large blocks from the dalvik pool. But I would also trust google's engineers to measure that kind of thing when making this decisionGabe Sechan– Gabe Sechan2024-08-12 05:07:17 +00:00Commented Aug 12, 2024 at 5:07
- The other cause of OOM on really old devices was that most devices had an OEM set limit on the amount of dalvik heap any one process could take. 128MB was a common limit for a while, and I had an app that would regularly hit it. If this limit still exists, it's now in the GB range. So that's another large set of oom issues that just isn't a problem anymore.Gabe Sechan– Gabe Sechan2024-08-12 05:08:42 +00:00Commented Aug 12, 2024 at 5:08
- @GabeSechan Correct me if I'm wrong please, as far as I understand if bitmap is stored in native heap instead of Dalvik heap, it motivates us to call .recycle() as soon as possible while it wan't mandatory when the bitmap was stored in the Dalvik heapКирилл Волков– Кирилл Волков2024-08-12 07:10:54 +00:00Commented Aug 12, 2024 at 7:10
- 1That's a pretty degenerate case- 99% of apps won't have that problem. I'd question why you're creating that many bitmaps, and if you are you should be using an LRU cache to hold them, and it would be that cache's job to recycle them. But yes, that would be a good reason to aggressively call recycle.Gabe Sechan– Gabe Sechan2024-08-15 16:30:01 +00:00Commented Aug 15, 2024 at 16:30
| Show 2 more comments