Status Update
Comments
vi...@google.com <vi...@google.com> #2
What steps are needed to reproduce this issue? Frequency of occurrence?
What is the expected output?
Which Android build are you using? (e.g. TQ3A.230705.001.A1)
Which device did you use to reproduce this issue?
Can you confirm if this issue is reproducible on a Pixel/Nexus device?
Are you reporting this as Developer or User?
Android bug report (to be captured after reproducing the issue)
For steps to capture a bug report, please refer:
Alternate method
Navigate to “Developer options”, ensure “USB debugging” is enabled, then enable “Bug report shortcut”. Capture bug report by holding the power button and selecting the “Take bug report” option.
Note: Please upload the bug report and screenshot to google drive and share the folder to android-bugreport@google.com, then share the link here.
kk...@gmail.com <kk...@gmail.com> #3
Please provide the requested information to proceed further. Unfortunately the issue will be closed within 7 days if there is no further update.
aa...@gmail.com <aa...@gmail.com> #4
It is not a bug but more like a feature request, so I don't have a log for it. I'm not familiar with changing the issue type, apologize for the confusion.
aa...@gmail.com <aa...@gmail.com> #5
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
vi...@google.com <vi...@google.com> #6
Could you help to close this issue?
lb...@gmail.com <lb...@gmail.com> #7
We are closing this issue based on above comment, Thanks
vi...@google.com <vi...@google.com> #8
vi...@google.com <vi...@google.com> #9
Thanks. I checked with my colleague, and
However, SoftReference is not recommended. ART GC usually reclaims SoftReferences only during a last ditch, avoid-OOME, block-the-allocation collection. But at that point, things have gotten rather janky already.
LruCache is still the best solution.
lb...@gmail.com <lb...@gmail.com> #10
@9 So if you agree that SoftReference shouldn't be used for Android, as in the docs (and in other places) from many years ago, why close this?
LruCache isn't the best solution because it is not efficient at all, and can still cause OOM.
The best solution would be what I wrote, to have a cache that can expand and shrink automatically by how the framework dictates that's allowed, so it prevents OOM while allowing absolute maximal memory usage for the cache.
Not to mention that Bitmaps have made the situation even weirder on Android, as they aren't saved on the heap memory anymore (was in the past, which could cause OOM, but at least you could manage it). Yet if you use a lot of memory by Bitmaps, you can't catch any exception/error of it, so it makes it even impossible to manage with LruCache, as it's unknown what's the max memory that the app can use that is outside of the heap memory...
lb...@gmail.com <lb...@gmail.com> #11
@9 I requested to have a better LruCache that has no clear boundaries, not the existing one. I've presented the disadvantages and you've ignored them all, while agreeing about alternatives that shouldn't be used.
And then you just say "best is LruCache". How is X better than X ? It's illogical conclusion...
lb...@gmail.com <lb...@gmail.com> #12
@9 You also say 36933020 is obsolete , yet you reached the same conclusion that Google wrote there:
So nothing has changed and this is why I request for a better solution.
vi...@google.com <vi...@google.com> #13
I think that you pointed out the known caveat of LrcCache
, as the javadoc points out
There is no specific size or formula that suits all applications, it's up to you to analyze your usage and come up with a suitable solution. A cache that is too small causes additional overhead with no benefit, a cache that is too large can once again cause java.lang.OutOfMemory exceptions and leave the rest of your app little memory to work with.
For your original request,
please offer something that automatically uses memory as needed, without setting a boundary,
We don't recommend a cache without a specific size, for LruCache
or a cache based on SoftReference
, because it will result in one of OutOfMemoryError
/ jank / early clearance of SoftReference in the older implementation. We don't have a GC that can avoid all of these problems if the application doesn't choose an appropriate size of the cache.
However, you can still architect your cache for your own application and purpose, because ART can't determine a good cache eviction strategy for your application, even though SoftReference
is guaranteed to avoid OOME. If you use SoftReference-based cache, your application will need additional mix of cache eviction strategies, including a cache size limit, least-recent-used, time expiration, etc, to avoid janks. Application shouldn't solely rely on GC to evict members in a SoftReference-based cache. You may consider more than 1 layers of cache, e.g. a very small cache strongly-referencing members avoided being GC-ed too early.
lb...@gmail.com <lb...@gmail.com> #14
Only point you've missed is what happens if you use various SDKs, each uses its own LruCache with size limit, so if they all get filled, it will reach OOM and you won't have any way to fix it.
That's why I made the request. We need something that:
1. Isn't bound as there is no such a thing as "appropriate size"
2. Protection against OOM, including when using some dependencies that would use it.
3. Protection against being released too soon.
4. Customizable, with various rules that can be added and applied.
Description
You want to have a large cache so that you will reach everything easily, but also not too large to avoid taking too much memory.
So, please offer something that automatically uses memory as needed, without setting a boundary, and if the GC decides that something isn't in use for a long time, let it free it by itself.
You could also set how important each item is, or for how long do you think you will want it, but the point is that it will never cause OOM because if the GC needs to reclaim memory, it will know it can free it from there too (for unused items of course)