问题描述
我正在研究一个从数据库中读取大量数据到 Map< String,Map< String,Map< String,String>>>< / $ c的应用程序$ c>,处理它,并使用内部xml编写器将处理后的报告写入电子表格。整个运行可能需要大约12个小时。
我发现我得到了
在线程CursorController-Thread-0中的异常java.lang.OutOfMemoryError:Java堆空间$ b $在java.lang.AbstractStringBuilder。< init>(AbstractStringBuilder.java:45)
在java.lang.StringBuilder。< init>(StringBuilder.java:68)
当我试图写这个巨型文件。出于这个原因,我认为最好在完成处理时写入每一个 我的问题是,如何确保 完成后通过键 这会将 I am working on an application which reads in a huge amount of data from a database into a I'm finding I'm getting When I attempt to write this jumbo file. For this reason I think it would be best to write each My question is, how can I make sure that the Once you're done with the This will "null" out the entry in the 这篇关于用HashMap进行Java内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! Map< String,Map< String,String>>< / code>(注意更深一层)。 / p>
Map< String,Map< String,String>>
在我写完后,它不会保留在内存中,因为Map >>仍然会包含它?
key
映射到 Map< String,Map< String,String>>
做
hugeMap.remove(key);
hugeMap
并使 Map< String,Map< String,String>>>
符合垃圾回收的条件(即永远不会造成堆空间不足) 。Map<String,Map<String,Map<String,String>>>
, processes it, and writes the processed reports to a spreadsheet using an in-house xml writer. The whole run can take about 12 hours.Exception in thread "CursorController-Thread-0" java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:45)
at java.lang.StringBuilder.<init>(StringBuilder.java:68)
Map<String,Map<String,String>>
(notice that's a layer deeper)as it's finished processing.Map<String,Map<String,String>>
is not retained in memory after I write it, since the Map>> will still contain it?Map<String,Map<String,String>>
mapped to by the key "key"
you simply dohugeMap.remove("key");
hugeMap
and make the Map<String,Map<String,String>>
eligible for garbage collection (i.e., never be part of causing a heap space out of memory).