有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java内存泄漏发生在ArrayList部分。我可以用SoftReference忽略它吗?

由于当前的内存泄漏问题,我感到压力很大。 我总是使用Allocation Tracking进行内存泄漏检查

使用ArrayList时,我的大多数应用程序都存在内存泄漏

enter image description here

发生内存泄漏源

private  ArrayList<SoftReference<OutputInputPair>> pairs = new ArrayList<SoftReference<OutputInputPair>>();

//record start...
@Override
public void process() {
    //get record camera preview file into queue
    for (SoftReference<OutputInputPair> pair : pairs ) {
         OutputInputPair actualPair = pair.get();
         actualPair.output.fillCommandQueues();
         actualPair.input.fillCommandQueues();
    } 

    //when record stop. stopped = true
    while (!stopped) { //recording...
        for (SoftReference<OutputInputPair> pair : pairs) {
             recording(pair);
        }
    }
 }

while(!stopped) {
     for (SoftReference<OutputInputPair> pair : pairs) {
          recording(pair);
     }
}

在停止录制之前,recording ()将无限期地执行

在这一部分,由于内存最大

I作为临时措施,使用SoftReference

啊,当记录停止时,那部分就没有内存了。 只有在记录开始时,才会发生内存泄漏 一般来说,当我使用SoftReference时,应用程序不会死掉。而且不会发生OutOfMemory

但我知道,即使使用SoftReference,分配跟踪工具也知道内存泄漏发生

所以我基本上想修复这部分的内存泄漏

如何解决这个问题

谢谢


共 (0) 个答案