开发者

Android: Out of memory error when loading text files. How to get available memory before loading files

开发者 https://www.devze.com 2023-03-28 04:04 出处:网络
I want to load a text file in开发者_如何学Python a wordprocessing apps. But I get out of memory error when files are of too big. I finalizedthat I can load upto 1 MB files. But sometimes I get out of

I want to load a text file in开发者_如何学Python a wordprocessing apps. But I get out of memory error when files are of too big. I finalized that I can load upto 1 MB files. But sometimes I get out of memory even for 1MB files. But I have to say before loading whether I can load files or not.

I tried for solution of finding maximum possible available memory, apart from freeMemory(), that is freememory + (maxmemory - totalmemory) which will give the total possible available memory for the application. (Say it will be around 18MB to 20 MB). But I get outofMemory error after completely utilizing the heap. say for example(24 MB).

  1. My question is really that (18MB to 20 mb) of "maximum possible available memory" is utilized for allocation when loading 1MB file.

  2. How much of memory should be available to load 1MB file.

  3. How can I roughly compute it.

  4. Is there any way out of PSS, Privatedirty. I couldn't understand much about PSS. But I couldn't get much info regarding of summing up in article "How to discover memory usage of my application in Android"

Thanks


Remember, the way you store the files in variables matters quite a lot. Using char array manually is one of the most memory-efficient ways, but you still need to account for every character taking 16 bits, or 2 bytes. So, if you have text file using some 8-bit encoding and you load it into char array, it takes twice as much space.

0

精彩评论

暂无评论...
验证码 换一张
取 消