I have an application in which the first action displays a loading animation and appears to significantly increase memory usage - with animation that the application uses about 30 MB, and without it less than 10 MB.
The corresponding code is as follows:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.load_application); StartLoadingAnimation(); } private void StartLoadingAnimation() { frameAnimation = new AnimationDrawable(); for(int i = 1; i <= 64; i++) { String index = i < 10 ? "00" + i : "0" + i; int frameIdentifier = getResources().getIdentifier("loading_icon_" + index, "drawable", getPackageName()); frameAnimation.addFrame(getResources().getDrawable(frameIdentifier), 70); } ImageView imageCafeLoading = (ImageView) findViewById(R.id.ImageCafeLoading); imageCafeLoading.setBackgroundDrawable(frameAnimation); imageCafeLoading.post(new LoadingImageStarter()); } private class LoadingImageStarter implements Runnable { public void run() { frameAnimation.setOneShot(false); frameAnimation.start(); } }
It seems that the completion of the operation when moving to the next one does not matter, the memory usage is still much higher with the animation.
How can I free this memory upon transition from activity or its destruction?
source share