How to solve a memory problem

Friends, I’m working on an application that contains so many images and animations. Why, after launching the application 2.3 times, it automatically crashes, and the log cat shows a memory problem. What will be the solution?

+1
source share
1 answer

It is best to create a class that extends the application. This application class will give you an onlowmemory () callback whenever the application goes into low memory. there you can write

public void onLowmemory() { Runtime.getRuntime().gc(); } 

which will invoke the GC system method. When you start the garbage collector, android will garbage all unused objects.

There is another way to solve this problem. In animation, you can call Runtime.getRuntime (). Gc (); to call the garbage collector. also in the onDestroy () action, the u method can call Runtime.getRuntime (). gc ();

so your problem will be solved.

+7
source

Source: https://habr.com/ru/post/1438860/


All Articles