Issue #288 better memory/cache handling

This commit is contained in:
Jindra Pet��k
2013-08-20 07:00:34 +02:00
parent be55c77a05
commit e753ca9ece
3 changed files with 10 additions and 3 deletions
@@ -2542,6 +2542,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel
(new Thread() {
@Override
public void run() {
Helper.freeMem();
try {
if (compressed) {
swf.exportFla(errorHandler, selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("parallelSpeedUp", Boolean.TRUE));
@@ -2551,6 +2552,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel
} catch (IOException ex) {
View.showMessageDialog(null, translate("error.export") + ": " + ex.getLocalizedMessage(), translate("error"), JOptionPane.ERROR_MESSAGE);
}
Helper.freeMem();
Main.stopWork();
}
}).start();
@@ -504,4 +504,8 @@ public class Helper {
timeStr += Helper.padZeros(timeS, 2) + "." + Helper.padZeros(timeMs, 3);
return timeStr;
}
public static void freeMem(){
Cache.clearAll();
System.gc();
}
}
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.types.shaperecords;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.helpers.Cache;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.base.NeedsCharacters;
@@ -812,7 +813,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters {
+ "</svg>";
return ret;
}
private static HashMap<String, BufferedImage> cache = new HashMap<>();
private static Cache cache = Cache.getInstance(false);
public static void clearShapeCache() {
cache.clear();
@@ -834,8 +835,8 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters {
public static BufferedImage shapeToImage(List<Tag> tags, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, List<SHAPERECORD> records, Color defaultColor) {
String key = "shape_" + records.hashCode() + "_" + (defaultColor == null ? "null" : defaultColor.hashCode());
if (cache.containsKey(key)) {
return cache.get(key);
if (cache.contains(key)) {
return (BufferedImage)cache.get(key);
}
RECT rect = new RECT();
List<Path> paths = getPaths(rect, shapeNum, fillStyles, lineStylesList, /*numFillBits, numLineBits,*/ records);