Images fail to render after several minutes of app use [Android, RN 0.24]
Hi, I am in the process of building an app that relies on a relatively large amount of network-based images, loaded with the source={{uri: uri}} prop. This works well for a while, but after several minutes of using the app, it seems to have run out of memory for these images. At that point, instead of rendering, new images will either remain blank, or render a black box. The app also starts slowing down and becoming jittery. I have tried to debug with systrace, but I can't for the life of me get the newest version to show traces in any browser,
Since my app is image heavy, I have added the largeHeap directive to my manifest, which helped, but I know that there is a better solution. I also am making sure to request smaller-dimensioned versions of the images. Does anyone have experience freeing memory from network images? This is fairly urgent, and any advice would be most appreciated.
Sam
Same issue here. Even using RN 0.25.1
I tested it on 3 devices.
With getImageCacheSize() from react-native-http-cache I logged the image cache size every second.
After a while the cache stops growing.
On each device it stops at different cache sizes:
| Device | Limit |
|---|---|
| One Plus | 40659781 |
| Samsung Galaxy S4 | 24892319 |
| Nexus 5 | 22600605 |
Now I just bruteforce called clearImageCache() every 10 sec.
Didn't solve the problem.
Still after loading many pictures (maybe around 100 - 150), it stops.
So it's probably not related to the image cache, what was my first assumption. So the problem probably lies in fresco / the bindings to fresco.
New <Image> elements just stay white. No error.
@foghina You implemented some of the RN Android fresco stuff. Have any idea what could cause the problem?
Thanks in advance!
Good thinking, tim. I ran a similar profile on my app, checking the http cache size, the image cache size, and the total, and I noticed that the cache does seem to be regulating itself pretty well. So I think it's a memory problem with something other than the cache.
I am too having this problem recently, I'm using RN 0.25.1.
After using the app for a while, some images renders blank. I simply have to reset content and settings and install the app into my simulator again. All images render fine now.
"react-native": "^0.25.1", getting this as well rendering 10 images, rendering blank in a ListView, black image otherwise EDIT: IOS
Update: I've been using Android memory monitor to profile my image-heavy ListView, and no combination of overflow: hidden, removeClippedSubviews, or manual image destruction is yielding a memory reduction. It also doesn't help that onChangeVisibleRows doesn't fire on Android, so building a workaround seems exceedingly difficult. I noticed that images on a route that is then popped from the navigator can indeed be garbage collected, but for routes that are never popped, Images consume a pretty significant chunk of memory.
Any chance that this would fix it?
The solution to that issue was for iOS it looks like - and at this point I am more inclined to believe this is an application-level memory problem, not necessarily one limited to Images. They're just the easiest targets since they consume the largest amount of memory.
Hmm so one "Fix" would be to use WebView for those pictures. I found this library called react-virtualized so one could use that if you have a ListView with huge amounts of Images.
@timsuchanek how would a webview help? Better memory footprint??
No, but I think that uses the integrated Browser, which should be able to handle a lot of images without crashing Am 18.05.2016 2:49 vorm. schrieb "Samuel Purcell" <[email protected]
:
@timsuchanek https://github.com/timsuchanek how would a webview help? Better memory footprint??
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/facebook/react-native/issues/7408#issuecomment-219896072
Hmmm, that seems like a pretty good solution memory-wise, but I can't seem to get the images to resize, since I don't have control over that from WebView. Any advice?
It seems that the problem goes away after adding a key to the Image like:
<Image key={some-image-${index}}/>
I have been plagued with this problem as well, especially in debug mode running on Genymotion emulator. I have an app where doing an item selection in a scrollview gets data and shows other images. Sometimes it works, sometimes I get blank images as well. I also do a complex render of up to 200 images in my scrollview and over time will see large numbers of them coming up blank.
As a lot of react-native is based on poking around the internet and using the almost non-existent code examples, I know that I am not rendering correctly. Probably need to do a more (if image has loaded, good, if not get it loaded approach similar to the listview datachanged examples). I've spent a lot of time on this issue, but it is getting too time consuming to find it. Hopefully others will see this post and perhaps show the way they are rendering images.
this is happening to me on RN 0.27.2 as well. i'm going to try workaround provided by @holyxiaoxin
ok the solution didn't work for me, adding a key to images (I render around 200 of them) still gives me blank images, any idea anyone?
I'm also having a similar problem. When I add too many images to my app, they just stop loading. I'm seeing the following in adb logcat:
100s of messages that look like this:
W/unknown:CloseableReference(18531): Finalized without closing: 134069e 195f257f (type = NativePooledByteBuffer)
W/unknown:CloseableReference(18531): Finalized without closing: a29d94c 30cedd95 (type = CloseableStaticBitmap)
And a few crashes like this:
W/InputMethodManagerService( 1130): Session failed to close due to DeadObject W/InputMethodManagerService( 1130): android.os.DeadObjectException W/InputMethodManagerService( 1130): at android.os.BinderProxy.transactNative(Native Method) W/InputMethodManagerService( 1130): at android.os.BinderProxy.transact(Binder.java:496) W/InputMethodManagerService( 1130): at com.android.internal.view.IInputMethodSession$Stub$Proxy.finishSession(IInputMethodSession.java:305) W/InputMethodManagerService( 1130): at com.android.server.InputMethodManagerService.finishSessionLocked(InputMethodManagerService.java:1632) W/InputMethodManagerService( 1130): at com.android.server.InputMethodManagerService.clearClientSessionLocked(InputMethodManagerService.java:1623) W/InputMethodManagerService( 1130): at com.android.server.InputMethodManagerService.clearCurMethodLocked(InputMethodManagerService.java:1654) W/InputMethodManagerService( 1130): at com.android.server.InputMethodManagerService.unbindCurrentMethodLocked(InputMethodManagerService.java:1603) W/InputMethodManagerService( 1130): at com.android.server.InputMethodManagerService.onServiceDisconnected(InputMethodManagerService.java:1680) W/InputMethodManagerService( 1130): at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1249) W/InputMethodManagerService( 1130): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1263) W/InputMethodManagerService( 1130): at android.os.Handler.handleCallback(Handler.java:739) W/InputMethodManagerService( 1130): at android.os.Handler.dispatchMessage(Handler.java:95) W/InputMethodManagerService( 1130): at android.os.Looper.loop(Looper.java:135) W/InputMethodManagerService( 1130): at com.android.server.SystemServer.run(SystemServer.java:290) W/InputMethodManagerService( 1130): at com.android.server.SystemServer.main(SystemServer.java:190) W/InputMethodManagerService( 1130): at java.lang.reflect.Method.invoke(Native Method) W/InputMethodManagerService( 1130): at java.lang.reflect.Method.invoke(Method.java:372) W/InputMethodManagerService( 1130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984) W/InputMethodManagerService( 1130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Is this happening on a device or on genymotion? Is it in debug mode our did you try a release version? Post the code
On Sep 26, 2016 8:56 PM, "Cxxxx100" [email protected] wrote:
I'm also having a similar problem. When I add too many images to my app, they just stop loading. I'm seeing the following in adb logcat:
100s of messages that look like this: W/unknown:CloseableReference(18531): Finalized without closing: 134069e 195f257f (type = NativePooledByteBuffer) W/unknown:CloseableReference(18531): Finalized without closing: a29d94c 30cedd95 (type = CloseableStaticBitmap)
And a few crashes like this: W/InputMethodManagerService( 1130): Session failed to close due to DeadObject W/InputMethodManagerService( 1130): android.os.DeadObjectException W/InputMethodManagerService( 1130): at android.os.BinderProxy.transactNative(Native Method) W/InputMethodManagerService( 1130): at android.os.BinderProxy. transact(Binder.java:496) W/InputMethodManagerService( 1130): at com.android.internal.view. IInputMethodSession$Stub$Proxy.finishSession(IInputMethodSession.java:305) W/InputMethodManagerService( 1130): at com.android.server. InputMethodManagerService.finishSessionLocked(InputMethodManagerService. java:1632) W/InputMethodManagerService( 1130): at com.android.server. InputMethodManagerService.clearClientSessionLocked( InputMethodManagerService.java:1623) W/InputMethodManagerService( 1130): at com.android.server. InputMethodManagerService.clearCurMethodLocked(InputMethodManagerService. java:1654) W/InputMethodManagerService( 1130): at com.android.server. InputMethodManagerService.unbindCurrentMethodLocked( InputMethodManagerService.java:1603) W/InputMethodManagerService( 1130): at com.android.server. InputMethodManagerService.onServiceDisconnected(InputMethodManagerService. java:1680) W/InputMethodManagerService( 1130): at android.app.LoadedApk$ ServiceDispatcher.doDeath(LoadedApk.java:1249) W/InputMethodManagerService( 1130): at android.app.LoadedApk$ ServiceDispatcher$RunConnection.run(LoadedApk.java:1263) W/InputMethodManagerService( 1130): at android.os.Handler. handleCallback(Handler.java:739) W/InputMethodManagerService( 1130): at android.os.Handler. dispatchMessage(Handler.java:95) W/InputMethodManagerService( 1130): at android.os.Looper.loop(Looper. java:135) W/InputMethodManagerService( 1130): at com.android.server. SystemServer.run(SystemServer.java:290) W/InputMethodManagerService( 1130): at com.android.server. SystemServer.main(SystemServer.java:190) W/InputMethodManagerService( 1130): at java.lang.reflect.Method.invoke(Native Method) W/InputMethodManagerService( 1130): at java.lang.reflect.Method. invoke(Method.java:372) W/InputMethodManagerService( 1130): at com.android.internal.os.ZygoteInit$ MethodAndArgsCaller.run(ZygoteInit.java:984) W/InputMethodManagerService( 1130): at com.android.internal.os. ZygoteInit.main(ZygoteInit.java:779)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/7408#issuecomment-249739072, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUnhsdXAa13IAAC0aH0uJeEJcP60seZks5quGnFgaJpZM4IYIrA .
This is on a device running a debug version.
I can't seem to reproduce the DeadObjectException today, perhaps it was unrelated. But here is some sample code that causes the CloseableReference warnings and the images stop loading:
import React from "react";
import {
AppRegistry,
Image,
ScrollView,
StyleSheet,
Text,
TouchableHighlight,
View
} from "react-native";
AppRegistry.registerComponent("AwesomeProject", () =>
React.createClass({
render() {
var imageMap = [
"https://avatars2.githubusercontent.com/u/22461323",
// ...
// More Images as necessary, I needed ~ 200 to trigger the issue
"https://avatars2.githubusercontent.com/u/22461323"
];
return (
<View>
<Text>Lots of Images</Text>
<ScrollView
horizontal={true}
automaticallyAdjustContentInsets={false}
directionalLockEnabled={true}>
{imageMap.map((imageUri, i) =>
<TouchableHighlight key={i}>
<Image style={styles.image} source={{ uri: imageUri }} />
</TouchableHighlight>
)}
</ScrollView>
</View>
);
}
})
);
const styles = StyleSheet.create({
image: {
width: 150,
height: 150,
marginHorizontal: 20,
resizeMode: "contain"
}
});
Try something. First of all wrap the touchable highlights with a
Brian B. Canin [email protected]
858-945-5601 (cell)
On Wed, Sep 28, 2016 at 3:11 PM, Cxxxx100 [email protected] wrote:
This is on a device running a debug version.
I can't seem to reproduce the DeadObjectException today, perhaps it was unrelated. But here is some sample code that causes the CloseableReference warnings and the images stop loading:
import React from "react"; import { AppRegistry, Image, ScrollView, StyleSheet, Text, TouchableHighlight, View } from "react-native";
AppRegistry.registerComponent("AwesomeProject", () => React.createClass({ render() { var imageMap = [ "https://avatars2.githubusercontent.com/u/22461323", // ... // More Images as necessary, I needed ~ 200 to trigger the issue "https://avatars2.githubusercontent.com/u/22461323" ];
return ( <View> <Text>Lots of Images</Text> <ScrollView horizontal={true} automaticallyAdjustContentInsets={false} directionalLockEnabled={true}> {imageMap.map((imageUri, i) => <TouchableHighlight key={i}> <Image style={styles.image} source={{ uri: imageUri }} /> </TouchableHighlight> )} </ScrollView> </View> ); } }));
const styles = StyleSheet.create({ image: { width: 150, height: 150, marginHorizontal: 20, resizeMode: "contain" } });
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/7408#issuecomment-250268618, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUnhhe_Og8DA0ZMoSxecd86nTKs83B1ks5qurvmgaJpZM4IYIrA .
I made the suggested changes, but I'm still seeing the warnings and the images stop loading.