Tag: 内存漏出内存

Java收集和内存优化

我为自定义表写了一个自定义索引,该表使用500MB的堆来表示500k字符串。 只有10%的字符串是唯一的; 其余的都是重复的。 每个字符串的长度为4。 我如何优化我的代码? 我应该使用另一个系列吗? 我试图实现一个自定义字符串池来节省内存: public class StringPool { private static WeakHashMap map = new WeakHashMap(); public static String getString(String str) { if (map.containsKey(str)) { return map.get(str); } else { map.put(str, str); return map.get(str); } } } private void buildIndex() { if (monitorModel.getMessageIndex() == null) { // the index, every columns create an […]