java - Memory not being released when Activity is closed -


i have 1 main activity. start sub activities tab. on closing sub activities memory isn't released using sub tab. memory increases every time on opening other tabs.

after time application crashed:

public class main extends activity {  public static activity activity;  private bundle saveinstance;      @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      this.activity = this;      this.saveinstance = savedinstancestate;      application app = application.getsharedinstance();      setcontentview(r.layout.activity_main); }  @override public boolean oncreateoptionsmenu(menu menu) {     getmenuinflater().inflate(r.menu.activity_main, menu);      return true; }  @override public void onbackpressed() {     // super.onbackpressed();     alertutills.showquitdialog(main.this); }  @override public boolean onoptionsitemselected(menuitem item) {      final tabhost tabhost = (tabhost)             .findviewbyid(android.r.id.tabhost);      localactivitymanager mlocalactivitymanager = new localactivitymanager(             this, false);     mlocalactivitymanager.dispatchcreate(saveinstance);     tabhost.setup(mlocalactivitymanager);      switch (item.getitemid())     {      case r.id.create_new:     {         if (commonutilities.istabnotexist(tabhost, "newproject"))         {             tabspec spec2 = tabhost.newtabspec("newproject");              intent in = new intent(this, activity_cretatenew.class);             in.setflags(intent.flag_activity_clear_top);             spec2.setcontent(in);             spec2.setindicator("new project");             tabhost.addtab(spec2);             tabhost.setcurrenttabbytag("newproject");         }          tabhost.setcurrenttabbytag("newproject");      }         break;      case r.id.open:     {          opendialog dialog = new opendialog(this, "open project", false,                 opendialogtype.corelog_open);         dialog.show();     }         break;      case r.id.menu_exit:          onbackpressed();          break;      case r.id.import_las:     {         if (iscurrentprojectexist())         {             if (commonutilities.istabnotexist(tabhost, "importlas"))             {                 tabspec spec2 = tabhost.newtabspec("importlas");                 intent in = new intent(this, lasimportwizard.class);                 spec2.setcontent(in);                 spec2.setindicator("import las");                 tabhost.addtab(spec2);             }              tabhost.setcurrenttabbytag("importlas");          }     }         break;      case r.id.import_coredata:     {         if (iscurrentprojectexist())         {             if (commonutilities.istabnotexist(tabhost, "coredata"))             {                 tabspec spec2 = tabhost.newtabspec("coredata");                 intent in = new intent(main.this,                         coredataimportwizard.class);                 spec2.setcontent(in);                 spec2.setindicator("core data import");                 tabhost.addtab(spec2);             }              tabhost.setcurrenttabbytag("coredata");          }     }         break;      case r.id.list_data:     {         if (isprojecthaswell())         {             if (commonutilities.istabnotexist(tabhost, "listdata"))             {                 tabspec spec1 = tabhost.newtabspec("listdata");                 intent in = new intent(main.this, listdatawindow.class);                 // in.setflags(intent.flag_activity_clear_top);                 spec1.setcontent(in);                 spec1.setindicator("list data");                 tabhost.addtab(spec1);              }              tabhost.setcurrenttabbytag("listdata");          }     }         break;       case r.id.basemap:     {         if (iscurrentprojectexist())         {             if (commonutilities.istabnotexist(tabhost, "basemap"))             {                 tabspec spec2 = tabhost.newtabspec("basemap");                 intent inbasemap = new intent(main.this, basemap.class);                 spec2.setcontent(inbasemap);                 spec2.setindicator("base map");                 tabhost.addtab(spec2);              }              tabhost.setcurrenttabbytag("basemap");         }     }         break;      case r.id.logplot:     {         if (isprojecthaswell())         {             if (commonutilities.istabnotexist(tabhost, "logplot"))             {                 tabspec spec2 = tabhost.newtabspec("logplot");                 intent intentlogplot = new intent(main.this,                         logplot_activity.class);                 spec2.setcontent(intentlogplot);                 spec2.setindicator("log plot");                 tabhost.addtab(spec2);             }             tabhost.setcurrenttabbytag("logplot");         }     }         break;      case r.id.show_hide_project_explorer:     {         framelayout framelayout = (framelayout) activity                 .findviewbyid(r.id.explorerframe);          if (item.ischecked() == true)         {             item.setchecked(false);             framelayout.setvisibility(view.gone);         }         else         {             item.setchecked(true);             framelayout.setvisibility(view.visible);         }          break;     }      }       return true; }  private boolean iscurrentprojectexist() {     return application.getsharedinstance().getcurrentproject() == null ? false             : true; }  private boolean isprojecthaswell() {     return iscurrentprojectexist()             && application.getsharedinstance().getcurrentproject()                     .getallwells().length != 0 ? true : false;  }    public static activity getmainactivity() {     return activity; } } 

run hprof or similar profiler. if happening, number of objects of tab activites increase. see whats holding onto references them, , fix them don't.

its kind of hard debug kind of thing without hprofs.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -