En el tecleo de lengüetas (botón de radio) Mi memoria que consigue el doble

Mi diseño es muy complejo. Tengo que hacer la página completa desplazable así que lo que hice es – tengo un adaptador del gridView para mis artículos de la rejilla y un adaptador de encargo que tiene cuatro lengüetas y después fijé mi gridview en ese adaptador de encargo. Entonces esta vista entera se fija en mi actividad principal que tiene un listview así que su ahora desplazamiento con la página llena pero el problema es con memoria.

Tengo 4 eventos del tecleo de la lengüeta en el adaptador de encargo de el cual estoy enviando esos acontecimientos del tecleo por poner adicional a la actividad principal donde tengo cuatro servicio de la tela y una condición que si la 1ra lengüeta se selecciona entonces la primera llamada del servicio de la tela ocurrirá y el nuevo adaptador fijará En la actividad principal.

Problema : cuando hago clic en la 1 ª pestaña mi tamaño de memoria es de 130 MB y en el clic de la 2 ª pestaña se eleva para duplicar y lo mismo sucede cuando hago clic en la tercera pestaña. Estoy utilizando carga perezosa para cargar mis imágenes que también mantiene mi caché, he intentado clear (), notifyDataSetChanged () pero no hace ningún cambio. Mi memoria está aumentando en cada clic de las pestañas.

Aquí está mi código:

GallaryLoginMainActivity :

public class GallaryLoginMainActivity<T> extends BaseClass { /** * Description:Declare the UI components. */ private List<ArrayList<HashMap<String, String>>> data = null; private ListView lstGallaryMain = null; public ArrayList<HashMap<String, String>> userDataActivity; public ArrayList<HashMap<String, String>> userDataSecondActivity; private ProgressDialog loadingDialog = null; LinkedHashMap<String, String> linkedMap; ArrayList<Assignment> assignmentArrayList; private String selectedTab = "popular"; private ImageLoader imageloader; // public static ArrayAdapter mAdapter; public ArrayAdapter mAdapter; /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetFiles() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap<String, String>(); gsp.parseXML(restService.getResponse()); // userDataActivity = new ArrayList<HashMap<String, String>>(); userDataActivity = gsp.userData; System.out.println("RR : userDataActivity from LoginMainAct :" + userDataActivity.size()); System.out.println("RR : from userdataactivty for item:" + userDataActivity.get(0).toString()); data.add(userDataActivity); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetFilesInfo() { // new Thread(new Runnable() { // public void run() { GallerySaxParserForGetFileInfo gisp = new GallerySaxParserForGetFileInfo(); try { RestService restService = new RestService(); linkedMap = new LinkedHashMap<String, String>(); System.out.println("From GallaryUserLoginMainActivity1 : " + restService.getResponse()); gisp.parseXML(restService.getResponse()); userDataSecondActivity = new ArrayList<HashMap<String, String>>(); userDataSecondActivity = gisp.userSecondData; data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } // } // }).start(); } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByPopuler() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap<String, String>(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList<HashMap<String, String>>(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); // }; // }.execute(); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByRecent() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap<String, String>(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList<HashMap<String, String>>(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByComment() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap<String, String>(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList<HashMap<String, String>>(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByNearBy() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap<String, String>(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList<HashMap<String, String>>(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } } /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallary_login_main_page_list); init(GallaryLoginMainActivity.this, R.id.main, getIntent()); data = new ArrayList<ArrayList<HashMap<String, String>>>(); imageloader = new ImageLoader(getApplicationContext()); Intent intent = getIntent(); if (intent.getExtras().getString("SELECTED_TAB") != null) { selectedTab = intent.getExtras().getString("SELECTED_TAB"); } /* * * This method is used to Show The loading dialog till the data * loads for main page. */ new AsyncTask<Void, Void, Void>() { protected void onPreExecute() { loadingDialog = ProgressDialog.show(GallaryLoginMainActivity.this, "", "Loading. Please wait...", true); } @Override protected Void doInBackground(Void... params) { return null; }; protected void onPostExecute(Void result) { if (selectedTab.equalsIgnoreCase("popular")) { MediaGetShortedFilesByPopuler(); } else if (selectedTab.equalsIgnoreCase("recent")) { MediaGetShortedFilesByRecent(); } else if (selectedTab.equalsIgnoreCase("commented")) { MediaGetShortedFilesByComment(); } if (mAdapter != null) { mAdapter = null; mAdapter.clear(); } if (mAdapter == null) { lstGallaryMain = (ListView) findViewById(R.id.lstGallaryMain); mAdapter = new GalleryCustomAdapterForMainPage<T>(GallaryLoginMainActivity.this, data); // mAdapter.notifyDataSetChanged(); } lstGallaryMain.setAdapter(mAdapter); if (loadingDialog != null && loadingDialog.isShowing()) { loadingDialog.dismiss(); } }; }.execute(); } } @Override protected void onResume() { System.gc(); super.onResume(); } @Override protected void onPause() { super.onPause(); System.gc(); } @Override public void onLowMemory() { super.onLowMemory(); imageloader.clearCache(); } @Override protected void onDestroy() { lstGallaryMain.setAdapter(null); userDataActivity = null; userDataSecondActivity = null; System.gc(); super.onDestroy(); } } 

GalleryCustomAdapterForMainPage :

  public class GalleryCustomAdapterForMainPage<T> extends ArrayAdapter<T> { public static int gridviewHeight = 0; private GridView refGridView; /** * Description:Declare the UI components. */ List<ArrayList<HashMap<String, String>>> data = null; public ArrayList<HashMap<String, String>> userDataActivity; public ArrayList<HashMap<String, String>> userDataSecondActivity; private ProgressDialog loadingDialog = null; // AQuery listAQ; private Activity mContext = null; private LayoutInflater inflater = null; Bitmap galleryBitmapHadnling = null; private PopupWindow mpopup; LinkedHashMap<String, String> linkedMap; Holder1 h1; GalleryMainActivityGridViewAdapter gmaga = null; private ImageLoader imageloader; /** * This method is use to set object that will control the listview * * @param activity * that creates this thing * @param data * bind to this listview */ // This Class is used to Declare a CustomAdapter that we use to join the // data set and the ListView public GalleryCustomAdapterForMainPage(Activity activity, List data) { super(activity, R.layout.gallery_main_page_content, data); this.mContext = activity; // listAQ = new AQuery(mContext); this.data = data; this.userDataActivity = this.data.get(0); System.out.println("userDataActivity is : " + userDataActivity); this.userDataSecondActivity = this.data.get(1); // listAQ = new AQuery(mContext); // Get a new instance of the layout view inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageloader = new ImageLoader(mContext); } // Total number of things contained within the adapter @Override public int getCount() { return this.data.size() - 1; } // create View for each item referenced by the Adapter @SuppressWarnings("deprecation") @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { /* create a new view of our layout and inflate it in the row */ // Inflate the layout convertView = inflater.inflate(R.layout.gallery_main_page_content, null); // System.gc(); h1 = new Holder1(); // Initialize the UI components h1.imgView_Gallery_Main_Background = (ImageView) convertView.findViewById(R.id.imgView_Gallery_Main_Background); h1.txtView_main_img_title = (TextView) convertView.findViewById(R.id.txtView_main_img_title); Typeface typeForTitile = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_bold_neue.ttf"); h1.txtView_main_img_title.setTypeface(typeForTitile); h1.texView_featured = (TextView) convertView.findViewById(R.id.texView_featured); Typeface typeForFeatured = Typeface.createFromAsset(getContext().getAssets(), "fonts/gotham_black_1.ttf"); h1.texView_featured.setTypeface(typeForFeatured); h1.txtView_assignment_detail = (TextView) convertView.findViewById(R.id.txtView_assignment_detail); Typeface typeAssignmentDetail = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold_1.ttf"); h1.txtView_assignment_detail.setTypeface(typeAssignmentDetail); h1.imgView_Main_TumbNail = (ImageView) convertView.findViewById(R.id.imgView_Main_TumbNail); h1.txtView_gallery_main_person_name = (TextView) convertView.findViewById(R.id.txtView_gallery_main_person_name); Typeface txtViewPersonName = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.txtView_gallery_main_person_name.setTypeface(txtViewPersonName); h1.txtView_gallery_main_views = (TextView) convertView.findViewById(R.id.txtView_gallery_main_views); Typeface txtViewViews = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.txtView_gallery_main_views.setTypeface(txtViewViews); h1.texView_gallery_main_comment = (TextView) convertView.findViewById(R.id.texView_gallery_main_comment); Typeface txtViewComments = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.texView_gallery_main_comment.setTypeface(txtViewComments); h1.texView_gallery_main_favorite = (TextView) convertView.findViewById(R.id.texView_gallery_main_favorite); Typeface txtViewFavorite = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.texView_gallery_main_favorite.setTypeface(txtViewFavorite); h1.btn_Gallery_Main_ShowMe = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Main_ShowMe); h1.btn_Gallery_Tab_Popular = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_Popular); Typeface TabPopular = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.btn_Gallery_Tab_Popular.setTypeface(TabPopular); h1.btn_Gallery_Tab_Popular.setChecked(true); h1.btn_Gallery_Tab_recent = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_recent); Typeface TabRecent = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.texView_gallery_main_favorite.setTypeface(TabRecent); h1.btn_Gallery_Tab_Commented = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_Commented); Typeface TabCommented = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.texView_gallery_main_favorite.setTypeface(TabCommented); h1.btn_Gallery_Tab_Nearby = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_Nearby); Typeface TabNearby = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.texView_gallery_main_favorite.setTypeface(TabNearby); h1.imgView_ForPlayVideo = (ImageView) convertView.findViewById(R.id.imgView_ForPlayVideo); if (userDataActivity.get(position).get("filetype").toString().endsWith("1")) { h1.imgView_ForPlayVideo.setVisibility(View.GONE); } else { h1.imgView_ForPlayVideo.setVisibility(View.VISIBLE); } // set the content in grid view of gallery main page h1.gridview_Gallery = (GridView) convertView.findViewById(R.id.gridview_Gallery); int gridHeight = (int) ((userDataActivity.size() / 3) * 140 * 1.80); System.out.println("gridHeigh is : " + gridHeight); if (h1.btn_Gallery_Tab_Popular != null) { h1.txtView_gallery_main_person_name.setText(" " + userDataActivity.get(position).get("user_name")); h1.txtView_main_img_title.setText(userDataActivity.get(position).get("title")); h1.txtView_gallery_main_views.setText(" | " + userDataActivity.get(position).get("hits") + " views"); h1.texView_gallery_main_comment.setText(" | " + userDataActivity.get(position).get("commentcount") + " "); h1.texView_gallery_main_favorite.setText(" | " + userDataActivity.get(position).get("votecount") + " "); imageloader.DisplayImage(userDataActivity.get(position).get("thumbUrl") + "/12", h1.imgView_Gallery_Main_Background); // h1.imgView_Main_TumbNail.setImageBitmap(getBitmap(userDataActivity.get(position).get("thumbUrl") // + "/12")); if (userDataActivity.get(position).get("publicUrl") != null) { imageloader.DisplayImage(userDataActivity.get(position).get("publicUrl") + "/14", h1.imgView_Gallery_Main_Background); } else { h1.imgView_Gallery_Main_Background.setBackgroundResource(R.drawable.loading); } } userDataActivity.remove(0); if (h1.gridview_Gallery != null) { // clearAdapter(); // setting the adapter // if (gmaga == null) { gmaga = new GalleryMainActivityGridViewAdapter(mContext, userDataActivity); // } h1.gridview_Gallery.setAdapter(gmaga); // Total number of things contained within the adapter int gridHeight1 = (int) ((h1.gridview_Gallery.getAdapter().getCount() / 3) * 120 * 1.80); h1.gridview_Gallery.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, gridHeight1)); h1.gridview_Gallery.setSelector(new ColorDrawable(color.transparent)); h1.gridview_Gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { Intent intent = new Intent(mContext, GalleryDetailPageActivity.class); System.out.println("pos:" + userDataActivity.get(position).get("id")); // This will send the items via intent to Gallery detail // page to display data on that page. intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); } }); } if (h1.btn_Gallery_Tab_Popular != null) { h1.btn_Gallery_Tab_Popular.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(mContext, GallaryLoginMainActivity.class); intent.putExtra("SELECTED_TAB", "popular"); intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); mContext.finish(); // } } }); } if (h1.btn_Gallery_Tab_recent != null) { h1.btn_Gallery_Tab_recent.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, GallaryLoginMainActivity.class); intent.putExtra("SELECTED_TAB", "recent"); intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); mContext.finish(); // } } }); } if (h1.btn_Gallery_Tab_Commented != null) { h1.btn_Gallery_Tab_Commented.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, GallaryLoginMainActivity.class); intent.putExtra("SELECTED_TAB", "commented"); intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); mContext.finish(); // } } }); } convertView.setTag(h1); } return convertView; } private class Holder1 { ImageView imgView_Gallery_Main_Background; TextView txtView_main_img_title; TextView texView_featured; RadioButton btn_Gallery_Tab_Popular; RadioButton btn_Gallery_Tab_recent; RadioButton btn_Gallery_Tab_Commented; RadioButton btn_Gallery_Tab_Nearby; ImageView imgView_Main_TumbNail; TextView txtView_assignment_detail; TextView txtView_assignment_name; TextView txtView_gallery_main_person_name; TextView txtView_gallery_main_views; TextView texView_gallery_main_comment; TextView texView_gallery_main_favorite; RadioButton btn_Gallery_Main_ShowMe; GridView gridview_Gallery; ImageView imgView_ForPlayVideo; } } 

GalleryMainActivityGridViewAdapter :

 public class GalleryMainActivityGridViewAdapter extends BaseAdapter { // AQuery listAQ; private Context mContext; int layoutResourceId; ArrayList<HashMap<String, String>> dataArray; ArrayList<Boolean> selected; private GallerySmartLazyLoader lazyloader; private ImageLoader imageloder; public static String dataExtension = " Views"; public GalleryMainActivityGridViewAdapter(Context context, ArrayList<HashMap<String, String>> resultArray) { this.mContext = context; // this.layoutResourceId = layoutId; this.dataArray = resultArray; // listAQ = new AQuery(mContext); lazyloader = new GallerySmartLazyLoader(mContext); imageloder = new ImageLoader(mContext.getApplicationContext()); // aa = new ArrayAdapter<Photo>(mContext, layoutResourceId); } public int getCount() { return dataArray.size(); } public void clear() { dataArray.clear(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } // BitmapFactory.Options options = null; // Bitmap cachedImage; @SuppressWarnings("deprecation") public View getView(int position, View convertView, ViewGroup parent) { String url = null; GalleryHolder holder = null; if (convertView == null) { convertView = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.gallery_main_page_grid_item, parent, false); convertView.setTag(holder); } else { holder = (GalleryHolder) convertView.getTag(); } holder = new GalleryHolder(); try { String thumbnail = dataArray.get(position).get("thumbUrl") + "/11"; holder.imgView_Grid_Thumbnail_Gallery = (ImageView) convertView.findViewById(R.id.imgView_Grid_Thumbnail_Gallery); if (holder.imgView_Grid_Thumbnail_Gallery != null) { } } catch (Exception e) { e.printStackTrace(); } holder.txtView_Grid_Name_Gallery = (TextView) convertView.findViewById(R.id.txtView_Grid_Name_Gallery); Typeface TabGridname = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); holder.txtView_Grid_Name_Gallery.setTypeface(TabGridname); if (holder.txtView_Grid_Name_Gallery != null) { // holder.txtView_Grid_Name_Gallery.getId()).text(dataArray.get(position).get("user_name")); holder.txtView_Grid_Name_Gallery.setText(dataArray.get(position).get("user_name")); Typeface txtViewForName = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); holder.txtView_Grid_Name_Gallery.setTypeface(txtViewForName); } ImageView v = holder.imgView_GridItem_Gallery = (ImageView) convertView.findViewById(R.id.imgView_GridItem_Gallery); if (holder.imgView_GridItem_Gallery != null) { String publicUrl = dataArray.get(position).get("publicUrl") + "/14"; imageloder.DisplayImage(publicUrl, holder.imgView_GridItem_Gallery); } holder.txtView_Grid_Views_Gallery = (TextView) convertView.findViewById(R.id.txtView_Grid_Views_Gallery); Typeface TabGriddetail = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); holder.txtView_Grid_Name_Gallery.setTypeface(TabGriddetail); if (holder.txtView_Grid_Views_Gallery != null) { if (isPopuler) { holder.txtView_Grid_Views_Gallery.setText(dataArray.get(position).get("hits") + dataExtension); } else if (isUpload) { GalleryMainActivityGridViewAdapter.dataExtension = dataArray.get(position).get("upload"); holder.txtView_Grid_Views_Gallery.setText(dataArray.get(position).get("upload")); } else if (isComments) { holder.txtView_Grid_Views_Gallery.setText(dataArray.get(position).get("commentcount") + dataExtension); } // else if (isNearby) { // aq.id(holder.txtView_Grid_Views_Gallery.getId()).text(dataArray.get(position).get("commentcount") // + dataExtension); // } Typeface txtViewForViews = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); holder.txtView_Grid_Views_Gallery.setTypeface(txtViewForViews); } holder.imgView_Grid_PlayVideo = (ImageView) convertView.findViewById(R.id.imgView_Grid_PlayVideo); if (holder.imgView_Grid_PlayVideo != null) { if (dataArray.get(position).get("filetype").toString().equals("1")) { holder.imgView_Grid_PlayVideo.setVisibility(View.GONE); } else { holder.imgView_Grid_PlayVideo.setVisibility(View.VISIBLE); } } return convertView; } class GalleryHolder { ImageView imgView_Grid_PlayVideo; ImageView imgView_Grid_Thumbnail_Gallery; TextView txtView_Grid_Views_Gallery; TextView txtView_Grid_Name_Gallery; ImageView imgView_GridItem_Gallery; } } 

foto

Introduzca aquí la descripción de la imagen

La descripción mostrada indica una posible pérdida de memoria. Revise mi respuesta para esta pregunta . Mi conjetura es que usted debe utilizar el contexto de la Application vez del contexto de la Activity en su código. Utilice el video en la respuesta mencionada para saber cómo identificar la fuga.

  • Android: liberación de la memoria asignada AnimationDrawable está utilizando hasta
  • ¿Será este ejemplo de Android seguro de usar, la memoria de fugas?
  • Límite de memoria interna para la tableta sin función de tarjeta SD
  • ByteBuffer no libera memoria
  • Dos preguntas sobre tamaños de montón máximo y memoria disponible en android
  • Detección de fugas de memoria nativas en el código JNI de Android
  • "Advertencia: no coloque las clases de contexto de Android en campos estáticos; Esto es una fuga de memoria (y también rompe el funcionamiento inmediato) "
  • Beneficios de GSON sobre el análisis normal de JSON
  • ¿Por qué el tamaño de mapa de bits es más grande en la memoria que en el disco en Android?
  • ¿Por qué EditText conserva el contexto de su actividad en Ice Cream Sandwich
  • Android: fugas de memoria al crear dinámicamente UI con fondos de recursos de imagen
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.