android - how to release memory occupied by bitmaps -
i creating app shows imageviews in circular manner. shows icons of settings e.g, bluetooth, wifi, etc. there's no out of memory error, after finishing activity, app still uses approx. 15mb ram on bitmaps according memory analyzer tool. how, can release bitmaps.
here's code creating circular view :
settingsimageviews = new arraylist<view>(0); // create settings icon views (int = 0; <= 12; i++) { imageview imageview = new imageview(this); if (i > 2 && != 10) { imageview.setimagedrawable(getsettingsicon(i - 3)); } else if (i == 10) { imageview.setimagedrawable(getresources().getdrawable(r.drawable.ic_key)); } else { imageview.setimagedrawable(null); } settingsimageviews.add(imageview); } settingscircularview = new circleview(this, circle_radius, settingsimageviews); parentlayout.addview(settingscircularview); for circular view i'm using code : custom circular view. placing of views
getsettingsicon method :
private drawable getsettingsicon(int settingid) { switch (settingid) { case 0:// bluetooth if (phonesetting.isbluetoothon()) return getresources().getdrawable(r.drawable.ic_bluetooth); else return getresources().getdrawable(r.drawable.ic_bluetooth_off); case 1:// wifi if (wifimanager.iswifienabled()) return getresources().getdrawable(r.drawable.ic_wifi_on); else return getresources().getdrawable(r.drawable.ic_wifi_off); . . . } } i tried recycle bitmaps in ondestroy method, when reopen activity crashes because of trying use recycled bitmap android.graphics.bitmap error.
i tried call system.gc(), app still uses 15mb ram.
i'm destroying views in ondestroy using unbinddrawables method :
private void unbinddrawables(view view) { if (view.getbackground() != null) { view.getbackground().setcallback(null); } if (view instanceof viewgroup && !(view instanceof adapterview)) { (int = 0; < ((viewgroup) view).getchildcount(); i++) { unbinddrawables(((viewgroup) view).getchildat(i)); } ((viewgroup) view).removeallviews(); } } after trying of above things not 1 mb got reduced. resources use approx. 4.5 mb.
are having oom problems?
since using getdrawable(r.drawable.superawesomefractal) android maintaining cache of bitmaps--for instance, if set same drawable on 2 different imageviews android not allocating twice space. say, since not explicitly creating/decoding/using bitmaps, unless seeing actual problems such oom exception, don't need worry releasing them or recycling allocations--android handle you. incidentally why getting exception trying reuse recycled bitmap.
Comments
Post a Comment