Question

If your web application must run on embedded or low memory devices, is there any facility in JavaScript to manage low memory conditions at runtime so that you can use as much memory as possible for caching data, but be able to reliably purge such a cache as required?

An example would be an application that has a local logical data store, like a has map of data object that it uses rather than making new requests on the server repeatedly. I'd like to be able to fill that cache up to a watermark that can be determined at runtime in my JavaScript application.

I've not found anything thus far, but I'm hopeful I'm just missing something.

Was it helpful?

Solution

No. The browser doesn't expose memory usage statistics to JavaScript.

If you're trying to implement caching, you're probably better off leveraging the browser's cache (e.g, using Expires: headers on AJAX responses) rather than trying to implement your own cache in JS.

OTHER TIPS

You can use localstorage or IndexDB to cache results for you (on most devices/browsers the actual size limits are quite good known), so there would not be any need for you to know the memory consumptions in javascript.

If you are using phonegap (http://www.phonegap.com) you can grap memory warnings easily within native code and dispatch them to javascript. I did that in several situations when it was possible to clear up the DOM and recalculate it later if needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top