Java 如何修复Android中的outofmemory错误?
我们经常遇到内存错误,所以应用程序会崩溃。我们的要求就像应用程序在位置更改时获取gps位置,并将其添加到arraylist中。利用此gps数据,采用了一种算法对gps数据进行压缩。 它每1分钟运行一次,并在线程中执行。但有时内存会很高,我会发布一段代码,在上面我的内存会增加 问题是下面的for循环无法执行多达85次的计算Java 如何修复Android中的outofmemory错误?,java,android,memory,arraylist,Java,Android,Memory,Arraylist,我们经常遇到内存错误,所以应用程序会崩溃。我们的要求就像应用程序在位置更改时获取gps位置,并将其添加到arraylist中。利用此gps数据,采用了一种算法对gps数据进行压缩。 它每1分钟运行一次,并在线程中执行。但有时内存会很高,我会发布一段代码,在上面我的内存会增加 问题是下面的for循环无法执行多达85次的计算 请帮我解决这个问题。 有人知道我们如何解决这个问题吗 encodep=新对象[n_点-1][11]; 双倍和=0; 双和t=0; /*初始化sed概率表 *SED_分辨率=
请帮我解决这个问题。
有人知道我们如何解决这个问题吗
encodep=新对象[n_点-1][11];
双倍和=0;
双和t=0;
/*初始化sed概率表
*SED_分辨率=10;0.1
*SED_分辨率=100 0.01
*/
//最终双色分辨率=10;
//双色值计数=1/(双色)(tol__GTAround*色分辨率);
/*编码开始*/
Log.d(标签,
“编码开始”;
//ProgressNotification.Create(n_点);
AppPolar ap_new=新的AppPolar();
对于(int i=0;i<(n_点-1);i++){
//进度通知。通知(i);
double dxcurr=ap.xapp.get(i+1)-x_-code.get(i);
double dycurr=ap.yapp.get(i+1)-y_码get(i);
/*if(param.b_debug==1){
System.out.println(“ap.tapp.size=“+ap.tapp.size()+”);
System.out.println(“\t\u code=“+t\u code.size()+”);
}*/
double tinvcurr=(ap.tapp.get(i+1)-t_code.get(i));
ap_新极性(dxcurr、dycurr、tinvcurr、angcurr、tol_GTA、ratio_tol);
angcurr=ap_new.angcurr 0;
双app_spd=ap_new.spdapp;
双tol_spd=ap_new.tol_spd;
双app_ang=ap_new.angcurr0;
double app_dang=ap_new.dangapp;
双tol_dang=ap_new.tol_dang;
/*编码时间*/
Log.d(标签,
“时间编码开始……”
+一),;
double dt_codeval=Function.round(tinvcurr/mint_tinterv);
双和=函数和(概率);
双加和=delta\u dt/maxtsq;
List prob_ttmp=new ArrayList();
int prob_t_size=prob_t.size();
对于(int index=0;index=tpre-dttmp){
sqtmp=j;
打破
}
}
如果(sqtmp>(i-t_minseg))
sqtmp=i-(int)t_minseg;
如果(sqtmp<0)
sqtmp=0;
速度平均值SIG(spd_代码子列表(sqtmp,i),dt_代码子列表(sqtmp,i+1),
参数);
列表=函数
.populateList1(0,tol_spd,(MaxSpInd-1)*tol_spd);
List gausspdftmp=new ArrayList();
int-spdlistSize=spdlist.size();
for(int index=0;index
您可以在清单文件中使用android:largeHeap=“true”请求更大的堆大小,但这在任何预蜂窝设备上都不起作用。在2.3之前的设备上,您可以使用VMRuntime类,但这不会起作用
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();
for (int i = 0; i < (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();
for (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();
for (int j = 0; j < tappSize; j++) {
if (ap.tapp.get(j) >= tpre - dttmp) {
sqtmp = j;
break;
}
}
if (sqtmp > (i - t_minseg))
sqtmp = i - (int) t_minseg;
if (sqtmp < 0)
sqtmp = 0;
estimatorSpeedMeanSig(spd_code.subList(sqtmp, i), dt_code.subList(sqtmp, i + 1),
param);
List<Double> spdlist = Function
.populateList1(0, tol_spd, (maxspdind - 1) * tol_spd);
List<Double> gausspdftmp = new ArrayList<Double>();
int spdlistSize = spdlist.size();
for (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 .........................................................................");