react-native ios, how to release local images from cache in low memory scenario?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm working with an app that utalizes a lot of local images i.e. images that have source like require(../assets/MyImage.png)
.
During development I didn't face any issues, however when I built my app for release on iphone 5s, I started getting random device restarts. After some research I found out that whenever I was browsing through my app and loading all these various images (some of them are heavy background images) they were persisted in iOS memory / RAM.
Memory was not cleared after I unmounted screens / navigated to different screens, it just kept growing while I was using my app and loading new images and eventually app crashed.
I found that there is an AppDelegate method in iOS called didReceiveMemoryWarning
that can be used to perform cache clearing when app is using too much memory, but I can't figure out what cache and how I should clear to remove react-native images in iOS?
Would appreciate any advice on the topic.
NOTE: I've read somewhere that iOS will auto manage memory, but after using XCode memory profiler and Instruments, I don't believe this is happening, it just keeps growing upwards whenever new resource is mounted on the screen.
Memory profiler output
ios react-native memory
add a comment |
I'm working with an app that utalizes a lot of local images i.e. images that have source like require(../assets/MyImage.png)
.
During development I didn't face any issues, however when I built my app for release on iphone 5s, I started getting random device restarts. After some research I found out that whenever I was browsing through my app and loading all these various images (some of them are heavy background images) they were persisted in iOS memory / RAM.
Memory was not cleared after I unmounted screens / navigated to different screens, it just kept growing while I was using my app and loading new images and eventually app crashed.
I found that there is an AppDelegate method in iOS called didReceiveMemoryWarning
that can be used to perform cache clearing when app is using too much memory, but I can't figure out what cache and how I should clear to remove react-native images in iOS?
Would appreciate any advice on the topic.
NOTE: I've read somewhere that iOS will auto manage memory, but after using XCode memory profiler and Instruments, I don't believe this is happening, it just keeps growing upwards whenever new resource is mounted on the screen.
Memory profiler output
ios react-native memory
2
Have you run the app through the memory profiler to check for leaks? Sounds like something is keeping your images in RAM and it may be a retain cycle.
– Dare
Jan 3 at 16:09
@Dare I updated question with screenshot from memory profiler. Asreact-native
dev, I'm mostly familiar with JavaScript side of it, so I'm not sure how to read this profiler, but I can tell that it's looking bad. Would appreciate suggestions / links to sources that could explain how to read this.
– Ilja
Jan 3 at 16:23
1
The profiler output seems to indicate you do have leaks. iOS can only manage your memory assuming you do not write a retain cycle. If that happens, ARC will never release your images. I would try and investigate for any obvious retail cycles in your controllers where children may be retaining their parents.
– Dare
Jan 3 at 16:27
add a comment |
I'm working with an app that utalizes a lot of local images i.e. images that have source like require(../assets/MyImage.png)
.
During development I didn't face any issues, however when I built my app for release on iphone 5s, I started getting random device restarts. After some research I found out that whenever I was browsing through my app and loading all these various images (some of them are heavy background images) they were persisted in iOS memory / RAM.
Memory was not cleared after I unmounted screens / navigated to different screens, it just kept growing while I was using my app and loading new images and eventually app crashed.
I found that there is an AppDelegate method in iOS called didReceiveMemoryWarning
that can be used to perform cache clearing when app is using too much memory, but I can't figure out what cache and how I should clear to remove react-native images in iOS?
Would appreciate any advice on the topic.
NOTE: I've read somewhere that iOS will auto manage memory, but after using XCode memory profiler and Instruments, I don't believe this is happening, it just keeps growing upwards whenever new resource is mounted on the screen.
Memory profiler output
ios react-native memory
I'm working with an app that utalizes a lot of local images i.e. images that have source like require(../assets/MyImage.png)
.
During development I didn't face any issues, however when I built my app for release on iphone 5s, I started getting random device restarts. After some research I found out that whenever I was browsing through my app and loading all these various images (some of them are heavy background images) they were persisted in iOS memory / RAM.
Memory was not cleared after I unmounted screens / navigated to different screens, it just kept growing while I was using my app and loading new images and eventually app crashed.
I found that there is an AppDelegate method in iOS called didReceiveMemoryWarning
that can be used to perform cache clearing when app is using too much memory, but I can't figure out what cache and how I should clear to remove react-native images in iOS?
Would appreciate any advice on the topic.
NOTE: I've read somewhere that iOS will auto manage memory, but after using XCode memory profiler and Instruments, I don't believe this is happening, it just keeps growing upwards whenever new resource is mounted on the screen.
Memory profiler output
ios react-native memory
ios react-native memory
edited Jan 3 at 16:21
Ilja
asked Jan 3 at 16:01
IljaIlja
10.6k51153287
10.6k51153287
2
Have you run the app through the memory profiler to check for leaks? Sounds like something is keeping your images in RAM and it may be a retain cycle.
– Dare
Jan 3 at 16:09
@Dare I updated question with screenshot from memory profiler. Asreact-native
dev, I'm mostly familiar with JavaScript side of it, so I'm not sure how to read this profiler, but I can tell that it's looking bad. Would appreciate suggestions / links to sources that could explain how to read this.
– Ilja
Jan 3 at 16:23
1
The profiler output seems to indicate you do have leaks. iOS can only manage your memory assuming you do not write a retain cycle. If that happens, ARC will never release your images. I would try and investigate for any obvious retail cycles in your controllers where children may be retaining their parents.
– Dare
Jan 3 at 16:27
add a comment |
2
Have you run the app through the memory profiler to check for leaks? Sounds like something is keeping your images in RAM and it may be a retain cycle.
– Dare
Jan 3 at 16:09
@Dare I updated question with screenshot from memory profiler. Asreact-native
dev, I'm mostly familiar with JavaScript side of it, so I'm not sure how to read this profiler, but I can tell that it's looking bad. Would appreciate suggestions / links to sources that could explain how to read this.
– Ilja
Jan 3 at 16:23
1
The profiler output seems to indicate you do have leaks. iOS can only manage your memory assuming you do not write a retain cycle. If that happens, ARC will never release your images. I would try and investigate for any obvious retail cycles in your controllers where children may be retaining their parents.
– Dare
Jan 3 at 16:27
2
2
Have you run the app through the memory profiler to check for leaks? Sounds like something is keeping your images in RAM and it may be a retain cycle.
– Dare
Jan 3 at 16:09
Have you run the app through the memory profiler to check for leaks? Sounds like something is keeping your images in RAM and it may be a retain cycle.
– Dare
Jan 3 at 16:09
@Dare I updated question with screenshot from memory profiler. As
react-native
dev, I'm mostly familiar with JavaScript side of it, so I'm not sure how to read this profiler, but I can tell that it's looking bad. Would appreciate suggestions / links to sources that could explain how to read this.– Ilja
Jan 3 at 16:23
@Dare I updated question with screenshot from memory profiler. As
react-native
dev, I'm mostly familiar with JavaScript side of it, so I'm not sure how to read this profiler, but I can tell that it's looking bad. Would appreciate suggestions / links to sources that could explain how to read this.– Ilja
Jan 3 at 16:23
1
1
The profiler output seems to indicate you do have leaks. iOS can only manage your memory assuming you do not write a retain cycle. If that happens, ARC will never release your images. I would try and investigate for any obvious retail cycles in your controllers where children may be retaining their parents.
– Dare
Jan 3 at 16:27
The profiler output seems to indicate you do have leaks. iOS can only manage your memory assuming you do not write a retain cycle. If that happens, ARC will never release your images. I would try and investigate for any obvious retail cycles in your controllers where children may be retaining their parents.
– Dare
Jan 3 at 16:27
add a comment |
1 Answer
1
active
oldest
votes
After various attempts to find a solution I ended up using following image package https://github.com/DylanVann/react-native-fast-image
It improved memory management and performance of my images. As additional benefit it allows to use WebP images in iOS project which reduced my bundle size substantially.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025819%2freact-native-ios-how-to-release-local-images-from-cache-in-low-memory-scenario%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After various attempts to find a solution I ended up using following image package https://github.com/DylanVann/react-native-fast-image
It improved memory management and performance of my images. As additional benefit it allows to use WebP images in iOS project which reduced my bundle size substantially.
add a comment |
After various attempts to find a solution I ended up using following image package https://github.com/DylanVann/react-native-fast-image
It improved memory management and performance of my images. As additional benefit it allows to use WebP images in iOS project which reduced my bundle size substantially.
add a comment |
After various attempts to find a solution I ended up using following image package https://github.com/DylanVann/react-native-fast-image
It improved memory management and performance of my images. As additional benefit it allows to use WebP images in iOS project which reduced my bundle size substantially.
After various attempts to find a solution I ended up using following image package https://github.com/DylanVann/react-native-fast-image
It improved memory management and performance of my images. As additional benefit it allows to use WebP images in iOS project which reduced my bundle size substantially.
answered Jan 16 at 7:48
IljaIlja
10.6k51153287
10.6k51153287
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025819%2freact-native-ios-how-to-release-local-images-from-cache-in-low-memory-scenario%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Have you run the app through the memory profiler to check for leaks? Sounds like something is keeping your images in RAM and it may be a retain cycle.
– Dare
Jan 3 at 16:09
@Dare I updated question with screenshot from memory profiler. As
react-native
dev, I'm mostly familiar with JavaScript side of it, so I'm not sure how to read this profiler, but I can tell that it's looking bad. Would appreciate suggestions / links to sources that could explain how to read this.– Ilja
Jan 3 at 16:23
1
The profiler output seems to indicate you do have leaks. iOS can only manage your memory assuming you do not write a retain cycle. If that happens, ARC will never release your images. I would try and investigate for any obvious retail cycles in your controllers where children may be retaining their parents.
– Dare
Jan 3 at 16:27