App not releasing memory immediately

Hi Team,

We have been working on one image processing app developed using react. In this app we are making the XMLHttpRequests to the server and storing the response in the cache which has around 200MB - 250MB of size. We are tracking the memory footprint using the Xcode instrument tool.

While downloading and rendering the data in app the Xcode instrument shows the memory footprint around 800MB - 1000MB. We are assuming that garbage collection is not working as expected or some resources are not released after use and because of this we get this high memory footprint for 200MB - 250MB data. If the data is changed then we are removing the existing data from cache and storing the new data. But here, when we delete the data from cache, it does not release the memory immediately and takes some time of 3 seconds or more.

In between this, the memory gets allocated to new data too and that increases the overall memory footprint of the app and in some cases the app is crashing. The maximum memory we have seen is average 1.5GB which varies with the device configuration. When we try the same activity on a safari browser where memory gets released immediately. If an app releases the initial acquired memory while loading new data we see very less app crashes. We need help to understand if there is a way to release the memory immediately to avoid the app crash.

To reproduce this scenario, we have created a simple app which creates an array with size of 100MB and checks the memory footprint using the Xcode instrument tool. When we create an array of 100MB size, sometimes it shows the memory footprint peak of around 700MB-800MB and when we clear the array by assigning it with an empty array it releases the memory after 2-3 seconds.

Created an array and then removed it and after removal of the array, created a new array of the same size immediately and again removed it. Because the memory is not released in time, if you repeat these steps a few times the app memory footprint will increase and that crashes the app.

App not releasing memory immediately
 
 
Q