3

I currently think about an architecture for one-page mobile-web-apps, let them work offline with a lot of data.

My concern is that loading and keeping all data loaded in objects is wasting too much memory. I think about older android phones, iphones etc.

Would it be a good idea to start with variables initialized whith json-strings of data-model-objects, which i load/parse into an object when i need them?
i could free the loaded object as soon as the use of the model changes (of course only if its unlikely that the object is needed in the near future)

or are those string-variables hold in memory anyway, so i dont save memory?

What is the difference in memory consumption between a javascript object and its (stringyfied JSON-)String?
UPDATE:
i found the answer to the question in this article about javascript object size.
so comparing a json-string and its corresponding loaded object shows that the string is smaller. Thats what i expected.

Would it be better to retreive the strings via ajax and put them into localStorage? After the anonymous ajax callback finishes the GC could do its job...

is this even the right direction? what is the best approach keeping data like that?
I know all this is very vague, so any help is highly appreciated!

Community
  • 1
  • 1
hc2p
  • 188
  • 1
  • 11
  • If you have just one big object it doesn't matter how you store or serialize it as you still need to decode it to memory in some point? Also you don't mention the size of the data so the question lacks the most crucial detail. – Mikko Ohtamaa Jan 18 '12 at 17:03
  • hi mikko, i dont want to have one big (init-)object as i see that makes no sense and difference in any way. I rather plan to have all models split up into several objects to keep them in memory or not. The size of these model-objects (or maybe arrays) can vary from only few entries to thousands of them. So i try to keep the memory consumption at the lowest – hc2p Jan 19 '12 at 09:46

1 Answers1

0

localStorage is stored on the real disk,so every time you read the data will not as quick as in a Object. localStorage is good for offline.if a large data don't require to offline and don't read too much often,just store it in an hidden will better.

unbuglee
  • 195
  • 1
  • 11