At the beginning of the program, the loading page ate 30m, then jumped to login, ate another 30m, and then. I removed the
loading background image, and the memory immediately became 39m. It is terrifying to imagine that such a large image eats up 30m of memory
. The
solution is
not to add a background image to the xml, use code to add it, and recycle it
private void initBg(){ Bitmap bm = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_reg); BitmapDrawable bd = new BitmapDrawable(this.getResources(), bm); bg_ll.setBackgroundDrawable(bd); } @Override protected void onDestroy() { if(bg_ll!=null){ BitmapDrawable bd = (BitmapDrawable)bg_ll.getBackground(); bg_ll.setBackgroundResource(0);//Don't forget to set the background to null to avoid the used a recycled bitmap error when onDraw refreshes the background if(bd!=null){ bd.setCallback(null); bd.getBitmap().recycle(); } } System.gc();//No gc system will not release background image memory immediately super.onDestroy (); }
Look at the result after ondestory gc after I changed the code