Preserving objects/variables in non-volatile storage

SUMMARY

Though I lack extensive programming experience, I am currently developing a hybrid mobile app with Cordova. The app will contain a substantial amount of static data which needs to be referenced periodically for basic operations. As the volume of objects is expected to reach close to 10,000, I am concerned that this may overload the device's memory.

My initial idea is to store the static data in local storage instead of declaring individual objects within the code itself. By utilizing a JSON file, I can access and reference the required information during each iteration of my loop without putting excessive strain on the device's RAM.

DETAILS

• Development tools include typescript and Cordova.

• Anticipating handling tens of thousands of static objects.

• Objects will adhere to specific interfaces as templates.

• Few objects will be accessed for information every minute.

• Basic operations will be carried out based on this information.

• Object IDs may need to be stored permanently for future use.

• Operations dictate which objects are referenced next.

INQUIRIES

I seek clarification on how objects are stored and whether the projected number of objects could overwhelm a mobile device's RAM capacity. Is it viable to store all static data in a JSON format and then selectively reference objects from the file when needed?

Answer №1

It's important to understand that modern operating systems do not always directly map an application's memory to the hardware RAM.

Imagine having a phone with only 256MB of total RAM, and your application ends up loading 128MB of data into memory. Does this mean you can only run one more application that requires 128MB of memory? What about the OS using memory itself? The truth is, the OS will transfer some data from RAM to secondary storage like a solid-state drive, creating space for your app and other apps to function efficiently. If the data moved out of RAM is needed again, the OS can retrieve it from the SSD back into RAM through a process known as paging. This complex system adds to the efficiency of the operating system's memory management without requiring manual intervention by your application code.

While the OS does handle memory allocation well, it is still beneficial to write memory-efficient code especially on mobile devices.

In the case of your example, storing static data in local storage is a good initial step. However, there are potential drawbacks to be wary of along with questions that should be addressed:

  • Is it possible to split the data so that only necessary parts are loaded at a time?
  • Can the data be stored in a more compressed structure such as Tries?
  • How often will the data need to be retrieved from local storage?
  • Could retrieving data from local storage cause delays, particularly if a loop performs numerous iterations each requiring extensive data retrieval?

Wishing you success in optimizing your memory usage!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to assign separate names for serialization and deserialization in MVC?

I've encountered a situation where I have a class with attributes such as [DataContract] and [DataMember]. Specifically, the Name property of the Origin is set to custom variables, matching the data provided by the API I'm working with. However, ...

What is the best way to combine the contents of one file into another file while maintaining the appropriate formatting using a shell

I am dealing with two JSON files - template.json and historique.json. The template.json file contains the following data: { "PTF_INSTALL_DATE": " 2020-03-31 09:12:10", "PTF_CONTENT": [ { "NAME": "api_batch_API", "CHECKED": "a ...

What issue are we encountering with those `if` statements?

I am facing an issue with my Angular component code. Here is the code snippet: i=18; onScrollDown(evt:any) { setTimeout(()=>{ console.log(this.i) this.api.getApi().subscribe(({tool,beuty}) => { if (evt.index == ...

Tips for correctly specifying the theme as a prop in the styled() function of Material UI using TypeScript

Currently, I am utilizing Material UI along with its styled function to customize components like so: const MyThemeComponent = styled("div")(({ theme }) => ` color: ${theme.palette.primary.contrastText}; background-color: ${theme.palette.primary.mai ...

Encountering a JSON format issue while attempting to perform a POST or PUT operation with express4-tedious

If you're looking to work with the 'Todo' app from sql-server-samples, you can find it here. This app is designed to quickly turn a SQL Server database into a REST API using minimal lines of code. However, I'm running into an issue wit ...

Building a dynamic SQL Server script for inserting JSON data

It seems like I am facing an issue with my attempt to create a single procedure for inserting data into multiple tables. Here's a snippet of the problem: DECLARE @jsondata varchar(MAX) Set @jsondata='[{"RecordId":1,"CreatedUser&quo ...

Is there a way to turn off linting while utilizing vue-cli serve?

I am currently running my project using vue-cli by executing the following command: vue-cli-service serve --open Is there a way to stop all linting? It seems like it's re-linting every time I save, and it significantly slows down the process of ma ...

PySpark - StructType does not support the object 'string indices must be integers' with data type <class 'str'> in PySpark

Encountering a TypeError when attempting to access JSON in string format inside a map function. Error Message: "TypeError: StructType cannot accept object 'string indices must be integers' in type " I have reviewed several posts on Stackoverflo ...

Error message: Unexpected character found at the beginning of JSON data - REST API using node.js and Express

Recently, I have embarked on the journey of learning REST API with node and express. My main goal is to achieve file read and write operations using APIs. However, a frustrating error arises when attempting to hit the API through Postman. Strangely enough, ...

MyApp is encountering issues resolving all parameters

I'm encountering an issue that none of the other similar questions have been able to help me solve. Can anyone offer assistance? I've already attempted removing parameters one by one, but I'm still stuck. Can't resolve all parameters f ...

Transferring a large volume of JSON objects to a database using API post requests

Currently, I'm faced with the challenge of sending a large amount of JSON objects to a database through API post calls. However, upon attempting to send all these objects individually, I encounter numerous HTTP errors, predominantly 400 errors. My in ...

Struggling to enable Google Cast functionality on Apache Cordova: Unhandled error - chrome is not recognized

Struggling to integrate Google Cast with Apache Cordova, I'm facing challenges due to outdated guides and plugins. Despite finding a recently updated plugin three months ago, I keep encountering this error: Uncaught ReferenceError: chrome is not defi ...

"The act of initializing an EntryComponent in Angular results in the creation of a brand

In my main component, app.component.ts, I have integrated a new service into the providers[] array and initialized it in the constructor: @Component({ selector: 'app-main', templateUrl: './app.component.html', styleUrls: ['. ...

Python code for extracting values from nested JSON structures with the possibility of some values being null

My objective is to extract the value of primary_ip as a variable by parsing the JSON data. Sometimes, primary_ip appears as "null". Below is an example of the JSON structure, code snippet, and the error message I encountered recently. { "count" ...

Guide to transforming an embed/nested FormGroup into FormData

Presenting my Form Group: this.storeGroup = this.fb.group({ _user: [''], name: ['', Validators.compose([Validators.required, Validators.maxLength(60)])], url_name: [''], desc: ['', Validators.compose([Valida ...

Tips for verifying the authenticity of JSON data within Laravel

Below is an example of the JSON data I am sending via Postman for the 'specification' field: { "specification": [ { "type": [ { "type": "Smartphone , Phablet , Notch Phone , Camera Phone , Selfie Phone", ...

Karma Unit test: Issue with accessing the 'length' property of an undefined value has been encountered

While running karma unit tests, I encountered a similar issue and here is what I found: One of my unit tests was writing data to a json file, resulting in the following error: ERROR in TypeError: Cannot read property 'length' of undefined a ...

What is the process for type checking a Date in TypeScript?

The control flow based type analysis in TypeScript 3.4.5 does not seem to be satisfied by instanceof Date === true. Even after confirming that the value is a Date, TypeScript complains that the returned value is not a Date. async function testFunction(): ...

How come the POST request does not return the JSON according to the specification in my Mongoose schema definition?

I'm encountering an issue with running a POST request on Postman. After running the POST request, I am only receiving a partial schema back, instead of the entire JSON as defined in my Mongoose schema. Here is the relevant code snippet: Model: &apos ...

Utilizing PushPlugin in Phonegap for iOS Integration

I am currently in the process of integrating push notifications into my iOS application using Phonegap, and I have encountered some confusion along the way. Initially, I was following a tutorial found at: The tutorial is generally easy to follow, but the ...