0

It's my first Java coding experience, so I had to search a lot of information, however I still have a problem.

In my app I must read a 4.5 Mb array to memory. As I see from Memory Monitor in Android studio, it is not deleted after pressing back and exiting to the desktop. It is not deleted by GC. Can I use the same array for the 2nd launch? The pointer to it (it's a global in MainActivity) is null every time, so I have to get a new array. But the previous isn't deleted. If I don't set the pointer to it to null and not call System.gc() in onPause(), the app crashes with OOM. I've tried putCharArray and getCharArray, still no use. Is there any way to use the same array? Or do I have to read it every time when I open the app? It happens even after just going to Settings and back from notification bar or turning on/off physical keyboard. Android 4.0.3 AVD.

Update Shame on me, I even haven't thought about indexing. Anyway As I know, Android has an app in cache after closing it with Back button. If I just create an array, but don't make it null in onPause, the memory isn't freed by GC (as I can see in Memory Monitor). But after opening the app again the pointer is null, even if I didn't null it. Is there any way to save the pointer and this structred not in file and check if it's still in cache after opening the app again in order not to reload the file? Not after only killing the process, but even for just moving it from screen when, for instance, Settings are opened.

1 Answers1

0

you either create a database and insert the data into it so it can be loaded on start or save it in your locally on the sd storage in a file, for an array i suggest this way and write the array into an json file:
https://stackoverflow.com/a/14706227/1173391

Community
  • 1
  • 1
Nickolaus
  • 4,785
  • 4
  • 38
  • 60