-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Big memory issues because of RN's and Fresco's usage of Object.finalize() #8711
Comments
More explanation on why finalizers really shouldn't be used: https://www.securecoding.cert.org/confluence/display/java/MET12-J.+Do+not+use+finalizers Quotes, that I think apply here:
= tiny memory leaks are quickly growing into larger ones.
= as long as enough heap space is available, native resources won't be cleared.
|
I opened another issue on Fresco facebook/fresco#1351 |
Agreed but there also usages in RN that should be fixed. Another relevant discussion: https://stackoverflow.com/questions/18042176/what-will-the-finalizer-thread-do-if-there-is-a-infinite-loop-or-deadlock-in-the
|
@facebook-github-bot label Android |
Fresco is not dependent on finalizers. Finalizers are used in Fresco as a safety measure - if Fresco is not abused finalizers will do nothing. |
One additional question: are you using animated gifs or webps anywhere? |
There are 11 usages, that do things, like the native release code here GifFrame. The immediate problems I see:
But generally: Execution of an object's finalizer may be delayed for an arbitrarily long time after the object becomes unreachable. Again, thank you for your work on Fresco and everything, but in my opinion (and that of any Java-expert you will ask) Fresco and RN need to get completely rid of the finalizers and explicitly release everything, if correct code is what's wanted. About using finalizers as a "safety-measure": another quote from: http://programmers.stackexchange.com/a/288724/48128
Also getting rid of the methods seem will give performance benefits:
Quote from Effective Java:
Conclusion: If you insist on keeping them, the only code that should be left in the methods is code that logs. This is ok: protected void finalize() throws Throwable {
try {
if (!isClosed()) {
L.error("not closed")
}
} finally {
super.finalize();
}
} Any calls to You cannot reliably fix these bugs and keep using finalizers, because on the next phone with different RAM or heap-size it will malfunction again. Heap-size is up to the phone-manufacturer by the way. |
@balazsbalazs Regarding why the manual GC doesn't clear: I think it's the memory problem. Also, i'm not sure if I followed the code correctly, but I think this call to Couldn't you get rid of a lot of synchronisation along with the finalizers? Also: It could be that the thread, which is invoking the finalizer, is from the application that uses Fresco and actually holding some other lock on |
I confirm that the there must be memory problem in Fresco. |
I got the logcat before the app crashed. The error is sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
|
Okay, the spec says it's guaranteed Another theory: In the screenshot you can see there are
|
@narychen Do you use animated gifs or webps? |
@fab1an Yes I do use gifs. But the problem could happen with only jpgs |
@narychen Can you do a ThreadDump using Android Studio and post it here? |
This might be related: https://stackoverflow.com/questions/37001181/android-finalizerdaemon-hanging-up |
@narychen Why did you delete the ThreadDump. I've linked to it in the google bugtracker. Can you also do a heapdump and check how many |
Ok here's a Threaddump from me: threads_report.txt |
@fab1an Because I think it's too long for people to read. |
And I post another issue on Fresco about the new clue I've found. |
I'm closing this issue in favor of #8780 and facebook/fresco#1363 |
While I see your point that having finalizers adds a marginal perf penalty I don't think that it's the major cause for the memory issues here. We're going to take another look at the perf penalty and the reason why you see so many FinalizerReferences - but I really don't think that's the cause for high memory usage. Both Facebook and Twitter are using Fresco - so if there would be any regression we'd see that in our graphs very-very early and it would effect us in a major way. |
@balazsbalazs It might be that the issues come up here and not at FB/Twitter, because the data-structures for the bridge, If the problem really is that RN is interfering with fresco's memory in a bad way, it could be tested by temporarily replacing RN's |
@fab1an I agree with you. The problem hasn't been solved and it often crashes down the whole app especially with GIF pictures. And my same app doesn't have the issue even on my old iphone 5, so the problem is android only. |
+1 |
+1 |
I did some memory profiling in Android Studio and noticed that there are huge amounts of
FinalizerReference
queueing up in the heap, which aren't garbage collected.Using
Object.finalize()
is a bad idea. Because of the way GC works, the queue can quickly fill up, which seems to be happen often in Android. Here is a discussion about this: http://stackoverflow.com/a/8355147/342947RN uses
Object.finalize()
in a couple of places, 2 of which seem to be fine because they log only. The usage inCountable.java
andHybridData.java
are problems, and I really really hope this get's fixed before a release, because it will mess with memory in unpredictable ways.I think this is also the reasons for the image-loading bugs mentioned here #8677 and ultimately in facebook/fresco#621.
Fresco uses finalizers even more than RN: search.
Here is a screenshot of my profile. This is reproducible and even after minutes of runtime and manually invoking GC this queue isn't cleared. As you can see, there's references to
CloseableStaticBitmap
from Fresco.I'm 98% sure this is also the reason for the image memory issue mentioned in the FAQ
The text was updated successfully, but these errors were encountered: