内存泄漏,内存不足

liangyue1994 2009-07-06 10:29:11
while (str_html.indexOf("<td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend) != -1) {
String sgindate = null;
String poddate = null;
String podtime = null;
String podplace =null;
String status = null;
String podreason = null;
podidx = str_html.indexOf("<td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend);
podidxend = str_html.indexOf("</td>", podidx);
sgindate = str_html.substring(podidx + 50, podidxend).trim();
System.out.println(sgindate);
if (Character.isDigit(sgindate.charAt(0))) { // 如果不是乱码
//poddate=sgindate.substring(0,10);
poddate = "07/01/2009";
podtime = "12:03 am";
//podtime = sgindate.substring(sgindate.length() - 8);
/*if (!Character.isDigit(poddate.charAt(9))) { // 如果是乱码
poddate = poddate.substring(0,9);
System.out.println(poddate);
if (!Character.isDigit(poddate.charAt(8))) {// 如果是乱码
poddate = poddate.substring(0,8);
}
}*/

} else {
poddate = "07/01/2009";
podtime = "12:03 am";
//podtime = sgindate.substring(sgindate.length() - 8);
}
/*if (!Character.isDigit(podtime.charAt(0))) {
podtime = podtime.substring(1);
}*/
podidx = str_html.indexOf("colspan=\"2\">", podidxend);
podidxend = str_html.indexOf("<img src=", podidx);
podreason = str_html.substring(podidx + 12, podidxend)
.trim();
podreason = podreason.substring(0, podreason.length() - 1);
if (podreason
.indexOf("<font class=\"txtContentRedSm\">", 0) != -1) {
int a = podreason.indexOf(
"<font class=\"txtContentRedSm\">", 0);
int j = podreason.indexOf("</font>", 0);
podreason = podreason.substring(a + 30, j).trim();
}
podidx = str_html.indexOf("colspan=\"3\">", podidxend);
podidxend = str_html.indexOf("</td>", podidx);
podplace = str_html.substring(podidx + 12, podidxend)
.trim();
if (podplace.indexOf("<img", 0) != -1) {
int b1 = podplace.indexOf("<img", 0);
podplace = podplace.substring(0, b1).trim();
}
podreason = HtmlReplace.Replace(podreason, "'", "''");
podplace = HtmlReplace.Replace(podplace, "'", "''");
sgindate = (new StringBuilder(String.valueOf(poddate)))
.append(" ").append(podtime).toString();
System.out.println(sgindate);
status = "DPR";
if (podreason.equals("Shipment delivered")
|| podreason
.equals("Delivered to broker as requested")
|| podreason
.equals("Delivery arranged, no signature is expected"))
status = "YES";
else
status = "DPR";
track = new String[9];
track[0] = hawb_no1;
track[1] = status;
track[2] = dc.Convert(sgindate, "MM/dd/yyyy hh:mm a",
Locale.ENGLISH, "yyyy-MM-dd HH:mm", Locale.ENGLISH);
track[3] = "";
track[4] = podreason;
track[5] = podplace;
track[6] = cpcode;
track[7] = awb_id;
Qtrack.add(track);
}

}
...全文
109 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
网络科技 2009-07-06
  • 打赏
  • 举报
回复
jvm的内存设置大点试试
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
它就一直循环下去,podidxend的值也循环出现,说明循环条出问题了。可是
str_html.indexOf(" <td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend) != -1;)
这一句是看这个字符串里面有没有匹配的字符串啊。
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
现在改成
for (int podidxend =0;str_html.indexOf("<td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend) != -1;) {
System.out.println(podidxend);
System.out.println("已经循环"+i++);
int podidx = str_html.indexOf("<td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend);
podidxend = str_html.indexOf("</td>", podidx);
podidx = str_html.indexOf("colspan=\"2\">", podidxend);
podidxend = str_html.indexOf("<img src=", podidx);
podidx = str_html.indexOf("colspan=\"3\">", podidxend);
podidxend = str_html.indexOf("</td>", podidx);
}
System.out.println("出循环");
刀锋的锋 2009-07-06
  • 打赏
  • 举报
回复
先顶一下,再慢慢看。呵呵。多检查下new的地方。。
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
目前的情况是我也知道内存泄露大部分原因是代码写的不好,我想问大家的,如果出现这种情况大概怎么去处理,谢谢大家了
阿士匹灵 2009-07-06
  • 打赏
  • 举报
回复
看看
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
因为在处理其中一个数据时出现了有50多条数据,所以处理到最后就会出现
Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
这段代码是处理一个大的字符串,根据匹配的结果添加到ArrayList Qtrack中
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
while (str_html.indexOf("<td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend) == -1) {
String sgindate = null;
String poddate = null;
String podtime = null;
String podplace =null;
String status = null;
String podreason = null;
podidx = str_html.indexOf("<td class=\"blacktext pL5_pT4_pB4_pR4\" colspan=\"1\">",podidxend);
podidxend = str_html.indexOf("</td>", podidx);
sgindate = str_html.substring(podidx + 50, podidxend).trim();
System.out.println(sgindate);
if (Character.isDigit(sgindate.charAt(0))) { // 如果不是乱码
poddate = "07/01/2009";
podtime = "12:03 am";
} else {
poddate = "07/01/2009";
podtime = "12:03 am";
}
podidx = str_html.indexOf("colspan=\"2\">", podidxend);
podidxend = str_html.indexOf("<img src=", podidx);
podreason = str_html.substring(podidx + 12, podidxend).trim();
podreason = podreason.substring(0, podreason.length() - 1);
podidx = str_html.indexOf("colspan=\"3\">", podidxend);
podidxend = str_html.indexOf("</td>", podidx);
podplace = str_html.substring(podidx + 12, podidxend).trim();
podreason = HtmlReplace.Replace(podreason, "'", "''");
podplace = HtmlReplace.Replace(podplace, "'", "''");
sgindate = (new StringBuilder(String.valueOf(poddate))).append(" ").append(podtime).toString();
System.out.println(sgindate);
status = "DPR";
if (podreason.equals("Shipment delivered")status = "YES";
else status = "DPR";
track = new String[9];
track[0] = hawb_no1;
track[1] = status;
track[2] = dc.Convert(sgindate, "MM/dd/yyyy hh:mm a",Locale.ENGLISH, "yyyy-MM-dd HH:mm", Locale.ENGLISH);
track[3] = "";
track[4] = podreason;
track[5] = podplace;
track[6] = cpcode;
track[7] = awb_id;
Qtrack.add(track);
}

}
阿士匹灵 2009-07-06
  • 打赏
  • 举报
回复
谢谢楼主给的分 呵呵
liangyue1994 2009-07-06
  • 打赏
  • 举报
回复
解决了,因为里面有一个条件有错,导致没有匹配的,但是又没有条件判断退出循环,所以一直在那循环。所以内存不足

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧