E
E
Elevferius2021-06-10 21:06:07
Java
Elevferius, 2021-06-10 21:06:07

The Java program slows down due to the frequent "capture" of a new "portion" of memory in small chunks of RAM. What to do?

I have a program written in java on android. This program runs the main() procedure on a background thread, which is the main loop and two nested ones. The essence of the program is that, at each iteration of the loop, it creates an array of data (with each loop 1 longer; like a stack). The new array is added to the previous ones in a two-dimensional array. Everything works well, only one problem. Java allocates 25 MB of RAM for the program, if more is needed, it still allocates 25 MB, etc., while, when allocating memory, the program slows down for 2-3 seconds. Soon, my "stack" becomes heavy, and the program needs to get 25 mb many times, because of which it freezes for a long time. How can I set in the program that it "grabbed" the memory not by 25 MB, but, say, by 100 MB? Free RAM on my phone is 1GB.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-06-10
@Elevferii

It is obvious to create your "stack" immediately of the required size outside the loop and fill it with data at iterations. But as aptly noted in the comments, you should not eat memory like that, especially in a mobile application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question