編輯:我認爲在解析xml的代碼中有一個邏輯錯誤,所以如果它正確寫入不應該有任何泄漏。奇怪的內存泄漏
所以我添加了我的項目一個AsyncTask類,我前段時間爲快速測試目的而寫,但它導致內存泄漏錯誤。
我相信它是負責任的,因爲當我刪除它泄漏問題消失。
這裏是堆轉儲文件(已轉換)http://www7.zippyshare.com/v/83628026/file.html
package com.example.xmldl;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.os.AsyncTask;
import android.util.Xml;
public class Dlxml extends AsyncTask<String, Void, Void> {
//adding or removing Override didnt matter just to let you know
InputStream istream = null;
protected Void doInBackground(String... url){
try {
downloadXml(url[0]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
private void downloadXml(String url) throws IOException {
try {
URL mUrl = new URL(url);
HttpURLConnection urlConnection = (HttpURLConnection) mUrl.openConnection();
istream = urlConnection.getInputStream();
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(istream, null);
parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, "resources");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() == XmlPullParser.TEXT) {
parser.nextTag();
}
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
istream.close();
}
}
}
什麼是實際的錯誤信息? –
這是內存泄漏... – 2012-09-12 13:23:07
如果您將轉儲視圖的屏幕截圖設置爲不強制我們在當前PC上設置MemAnalyzer,那將會非常簡單。謝謝 – AlexN