Thanks for the answers! Would you mind to suggest on the part about fragments and memory management ? I decided to implement the app with 3 activities and about 8 fragments. The activity number might slightly increase yet I think it's not the fragments but their bitmaps that gonna cause trouble with memory. For displaying the fragments I have two containers: a ViewPager(rotates 3-4 fragments) element fand a FrameLayout(displays strictly one fragment) element. Right now I'm simply hiding one type of container and show another - setVisibility or fragmentTransaction.hide (I haven't figured what is the difference between those apart from the latest gives an ability of adding to activity's backstack). Is their any better way of switching between those. Additionally, even if those fragments might not hold much memory by themselves - should I wrap those objects with SoftReference ? Any other precautions I should consider implementing it ? Thanks !
On Saturday, July 28, 2012 9:36:27 PM UTC+3, Romain Guy (Google) wrote: > > 1) Does ImageView.SetImageResource applied against the same id twice or >> thrice consumes memory for the same bitmap or uses a separate range for >> every imageview element ? >> > > I don't quite understand your question. When a Bitmap is loaded as a > Drawable (which is what ImageView does), it gets cached by the system > (using weak references.) This means that if do this: > > Drawable d1 = loadDrawable(R.drawable.myImage); > Drawable d2 = loadDrawable(R.drawable.myImage); > > you will get 2 different instances of Drawable, but the underlying Bitmap > will be loaded in memory only once. > > 2) same as 1. but for BitmapFactory.decodeResource >> > > Every time you call this method you will load a new instance of a Bitmap > object, which means you will use more memory. > > >> 3) What part of Bitmap object consumes the most memory. If it's "backbone >> memory object" than what is it ? Where can I elucidate the structure of >> bitmap memory for myself ? >> > > A Bitmap is backed by a byte array containing all the pixels. This is what > consumes the most memory. As of Android 3.0, this byte array can be found > in Bitmap.java, in previous versions of the platform the pixel storage > exists on the native side (you'd have to investigate SkBitmap.cpp.) > > -- > Romain Guy > Android framework engineer > [email protected] > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

