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;
}







1















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
enter image description here










share|improve this question




















  • 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


















1















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
enter image description here










share|improve this question




















  • 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














1












1








1








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
enter image description here










share|improve this question
















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
enter image description here







ios react-native memory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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. 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














  • 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








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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer




























      1














      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.






      share|improve this answer


























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 16 at 7:48









        IljaIlja

        10.6k51153287




        10.6k51153287
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            'app-layout' is not a known element: how to share Component with different Modules

            SQL update select statement