java - How to fix outofmemory error in Android? -
we getting outofmemory error , hence application getting crashed. our requirement app gets gps location on location change , adds arraylist. using gps data, have used 1 algorithm compress gps data compression. runs in every 1 min , executes in thread. after memory goes high , have posted block of code on have getting raise out of memory.
problem below loop unable execute 85 times calculations.
please me solve problem.
have idea how can tackle issue?
encodep = new object[n_point - 1][11]; double sum_thetalen = 0; double sum_t = 0; /* initializing sed probability table * sed_resolution=10; 0.1 * sed_resolution=100 0.01 */ // final double sed_resolution = 10; // double sed_value_count = 1 / (double) (tol_gtaround * sed_resolution); /* encoding starts */ log.d(tag, "encoding start ........................................................................."); // progressnotification.create(n_point); apppolar ap_new = new apppolar(); (int = 0; < (n_point - 1); i++) { // progressnotification.notify(i); double dxcurr = ap.xapp.get(i + 1) - x_code.get(i); double dycurr = ap.yapp.get(i + 1) - y_code.get(i); /*if (param.b_debug == 1) { system.out.println("ap.tapp.size=" + ap.tapp.size() + " "); system.out.println("_t_code=" + t_code.size() + " "); }*/ double tinvcurr = (ap.tapp.get(i + 1) - t_code.get(i)); ap_new.polar(dxcurr, dycurr, tinvcurr, angcurr, tol_gta, ratio_tol); angcurr = ap_new.angcurr0; double app_spd = ap_new.spdapp; double tol_spd = ap_new.tol_spd; double app_ang = ap_new.angcurr0; double app_dang = ap_new.dangapp; double tol_dang = ap_new.tol_dang; /* encoding time */ log.d(tag, "time encoding start ........................................................................." + i); double dt_codeval = function.round(tinvcurr / mint_tinterv); double sum = function.sum(prob_t); double add_to_sum = delta_dt / maxtsq; list<double> prob_ttmp = new arraylist<double>(); int prob_t_size = prob_t.size(); (int index = 0; index < prob_t_size; index++) { prob_ttmp.add((prob_t.get(index) / sum) + add_to_sum); } sum = 1 / function.sum(prob_ttmp); prob_ttmp = function.multiplyby(prob_ttmp, sum); dt_code.add(mint_tinterv * dt_codeval); t_code.add(t_code.get(i) + dt_code.get(i)); encodep[i][0] = function.clonelist(prob_ttmp); encodep[i][1] = dt_codeval; encodep[i][2] = -math.log(prob_ttmp.get((int) dt_codeval - 1)) / math.log(2d); sum_t = sum_t + (double) encodep[i][2]; prob_t = function.multiplyby(prob_t, gamma_dt); prob_t.set((int) (dt_codeval - 1), prob_t.get((int) (dt_codeval - 1)) + 1); prob_ttmp.clear(); prob_ttmp = null; log.d(tag, "time encoding stop ........................................................................." + i); /* encoding speed */ log.d(tag, "speed encoding start ........................................................................." + i); spd_code.add(app_spd); double codindtmp = function.round(app_spd / tol_spd) + 1; int maxspdind = (int) math.ceil(maxspd / tol_spd) + 1; if (i == 0) { prob_spdtmp = function.populatelist(1d / maxspdind, maxspdind); } else { double tpre = (double) t_code.get(i); double dttmp = t_spdmean; double dtmax = (dt.get(i) * trt_spd); if (dttmp < dtmax) dttmp = dtmax; int sqtmp = 0; int tappsize = ap.tapp.size(); (int j = 0; j < tappsize; j++) { if (ap.tapp.get(j) >= tpre - dttmp) { sqtmp = j; break; } } if (sqtmp > (i - t_minseg)) sqtmp = - (int) t_minseg; if (sqtmp < 0) sqtmp = 0; estimatorspeedmeansig(spd_code.sublist(sqtmp, i), dt_code.sublist(sqtmp, + 1), param); list<double> spdlist = function .populatelist1(0, tol_spd, (maxspdind - 1) * tol_spd); list<double> gausspdftmp = new arraylist<double>(); int spdlistsize = spdlist.size(); (int index = 0; index < spdlistsize; index++) { gausspdftmp.add(math.exp(-0.5 * ((spdlist.get(index) - estspd) / estspdvar) * (spdlist.get(index) - estspd) / estspdvar) / ((math.sqrt(2 * math.pi) * estspdvar))); } gausspdftmp = function.multiplyby(gausspdftmp, 1d / function.sum(gausspdftmp)); prob_spdtmp = function.add(gausspdftmp, delta_speed / maxspdind); prob_spdtmp = function.multiplyby(prob_spdtmp, 1d / function.sum(prob_spdtmp)); spdlist.clear(); spdlist = null; gausspdftmp.clear(); gausspdftmp = null; log.d(tag, "speed encoding stop ........................................................................." + i); }// else log.d(tag, "encoding stop .........................................................................");
you can use android:largeheap="true" in manifest file request larger heap size, not work on pre honeycomb devices. on pre 2.3 devices, can use vmruntime class, not work on gingerbread , above.
Comments
Post a Comment