I have a webapp with many (1000) buttons.
Each button reads an image (4032x3024 ~1.5MB - high resolution is needed) from a webserver when being clicked.
When running on a phone (Android Pixel3), after multiple clicks, when clicking on a button that was not clicked before, results in an error: net::ERR_OUT_OF_MEMORY when getting the image from the webserver.
I tried 2 use cases:
Use case1 - previously read images are released before loading the next image.
In this case I don't see the out-of-memory problem but the user experience is poor, because each image is retrieved from the webserver regardless if it has been read before.Use case2 - previously read images are not released.
In this case the experience is better when re-reading the same image (while the app is still responding), because the image is already cached. But at some point the program runs out of memory, and stops responding.
I use Chrome (version 79.0.3945.88) DevTools Memory and Perfomance tabs, and followed techniques from here to analyze the memory.
I don't see anything non-ordinary.
For example, I looked at the Allocation instrumentation over time
In useCase2, the memory grows as expected, when adding more images, but seems to be well below limit.
Checking the window.performance.memory.jsHeapSizeLimit
gives ~1GB.
Yet, when the out-of-memory problem occurs, the memory (in Javascript heap) is less than 20 MB
To avoid exceeding the memory limit, I want to check the amount of used memory, before reading the next image, and if the value exceed some threshold, release some used images.
In this way, the user may have better experience (e.g. if toggling between few images)
and always avoid the out-of-memory error.
Is there a way to check the memory used, programatically via Javascript in the browser?
(In Node.js "process.memoryUsage().heapUsed" can be used, but this does not work in the browser)
Thanks, Avner