我正在尝试调试此方法,但似乎没有任何效果...
我怀疑在条件语句中 pathName.add() 正在引起麻烦。执行此方法后,它会占用 50 MB,再执行一次它会占用 150 MB,直到达到 800 MB。但一切都是分配的空间。为什么 gc 不清理这个烂摊子???
Ps 此方法基于已用条件语句构造的给定路径创建目录
Ps Ps 方法 writeDir(...) 从 actionListener 中调用(当点击 gui ic 上的按钮时)。该按钮可以经常点击
Ps Ps Ps 我已经尝试了 Andreas 的建议,它部分工作。调用 pathName.clean() 后,伊甸园空间下降,但分配的空间仍在增长,达到最大值。
会对你的意见感兴趣:)谢谢
调用 writeDir(...)
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
progress(0);
XMLSaxLogic stax = new XMLSaxLogic(xmlPath);
DetectionFilter detectionFilter = new DetectionFilter(stax.getObjets());
try {
WriteFile writeFile = new WriteFile(detectionFilter.getDetectionList());
writeFile.writeDir(savedDirPath, detectionFilter.getHardwareList(), stax.getSiteName());
progress(100);
} catch (Exception a) {
System.out.println(a.getLocalizedMessage());
}
GetFileCount getFileCount = new GetFileCount(savedDirPath, detectionFilter.getDetectionList(), combo.getSelectedIndex());
getFileCount.getFile(savedDirPath.getAbsoluteFile().toString());
} catch (Exception a) {
System.out.println(a.getLocalizedMessage());
}
}
}
写入目录(...)
private ArrayList<String> detectList;
private String detection = null;
private String build = null;
private Set<String> pathName = new LinkedHashSet<>();
public WriteFile(ArrayList<String> detectList) {
this.detectList = detectList;
}
public void writeDir(File root, ArrayList<String> sevenElementList, ArrayList<String> oneElementList) {
for (String site : oneElementList) {
for (String s : sevenElementList) {
int indexx = s.indexOf("_");
int id = Character.getNumericValue(s.charAt(indexHardware - 1));
for (String detectionList : detectList) {
int index = detectionList.indexOf("_");
int sId = Character.getNumericValue(detectionList.charAt(index + 1));
if (detectionList.contains("Apple") && sId == id) {
detection = site.trim() + "/" + s + "/" + detectionList.trim();
pathName.add(format(detection));
} else if (detectionList.contains("Banana") && sId == id) {
build = detection.trim() + "/" + detectionList.trim();
pathName.add(format(build.trim()));
} else if (detectionList.contains("nananana") && sId == id) {
pathName.add(format(build.trim() + "/" + detectionList.trim()));
} else if (detectionList.contains("Watermelone") && sId == id) {
pathName.add(format(build.trim() + "/" + detectionList));
} else if (detectionList.contains("Orange") && sId == id) {
pathName.add(format(site.trim() + "/" + s.trim() + "/" + detectionList.trim()));
}
}
}
}
createDirTest(pathName, root);
}
private void createDirTest(Set<String> pathArray, File root) {
for (String s : pathArray) {
File subdir = new File(root, s);
subdir.mkdirs();
}
}
private String format(String toBeFormated) {
String toBeTrimmed = trimLastChar(toBeFormated.replace("ä", "ae").replace("ß", "ss").replace("ü", "ue").replace("ö", "oe").trim());
return toBeTrimmed;
}