简体   繁体   English

为什么我的程序在字节数组中保存1.5Gb内存?

[英]Why does my program hold 1.5Gb of memory in a Byte array?

I've been analyzing a heap dump due to some recent reported slowness. 由于最近发生的一些缓慢情况,我一直在分析堆转储。 Turns out there's a couple of 1.5GB byte arrays that get lodged there and I can´t trace where they come from. 事实证明,有两个1.5GB字节数组存放在该数组中,我无法追踪它们的来源。 Eclipse's MAT doesn´t show me the class that is holding such a huge chunk. Eclipse的MAT并没有向我展示包含这么大块内容的课程。 It just says "<system class loader>". 它只是说“ <系统类加载器>”。 Perhaps I'm not looking in the right place. 也许我找的地方不对。

在此处输入图片说明

What could be causing these two massive byte arrays being kept there? 是什么原因导致这两个大字节数组保留在那里? The app runs on Websphere Application Server. 该应用程序在Websphere Application Server上运行。 Here's some JVM info about the environment I'm running the app in. Thanks 这是有关我在其中运行应用程序的环境的一些JVM信息。谢谢

  • Compiled in: JVM 1.6 编译于:JVM 1.6
  • Environment Java version : JRE 1.7.0 Linux amd64-64 build 20130421_145945 (pxa6470sr4fp1ifix-20130423_02(SR4 FP1+IV38579+IV38399+IV40208) ) 环境Java版本:JRE 1.7.0 Linux amd64-64 build 20130421_145945(pxa6470sr4fp1ifix-20130423_02(SR4 FP1 + IV38579 + IV38399 + IV40208))
  • Virtual machine version : VM build R26_Java726_SR4_FP1_2_20130421_2353_B145945 虚拟机版本:VM内部版本R26_Java726_SR4_FP1_2_20130421_2353_B145945
    Just-In-Time(JIT) compiler switch, Ahead-Of-Time (AOT) compiler switch, Compiler version : r11.b03_20130131_32403ifx4 即时(JIT)编译器开关,提前(AOT)编译器开关,编译器版本:r11.b03_20130131_32403ifx4
  • Garbage collector version : GC - R26_Java726_SR4_FP1_2_20130421_2353_B145945_CMPRSS 垃圾收集器版本:GC-R26_Java726_SR4_FP1_2_20130421_2353_B145945_CMPRSS
  • Java Heap Information Java堆信息
    • -Xmx (Maximum Java heap size) : 4096m -Xmx(最大Java堆大小):4096m
    • -Xms (Initial Java heap size) : 1024m -Xms(初始Java堆大小):1024m
    • -Xscmx (Java class data sharing cache size) : 90M -Xscmx(Java类数据共享缓存大小):90M
    • -Xscmaxaot (Maximum number of bytes in the cache that can be used for AOT data) : 4M -Xscmaxaot(高速缓存中可用于AOT数据的最大字节数):4M

Edit: 编辑:

These two byte arrays instances are not defined directly in my code. 这两个字节数组实例未在我的代码中直接定义。 I do however use these methods constantly, within a util class, in order to read and write payroll bulk files. 但是,我确实在util类中不断使用这些方法,以便读写工资批量文件。 I wonder whether the constant creation of temporary files and input streams has anything to do with it. 我想知道是否不断创建临时文件和输入流与它有关。

public abstract class IOUtils {
public static Logger log = LoggerFactory.getLogger(IOUtils.class);
private IOUtils() {}
public static String readFirstLine(File f) {
    String line = null;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(f));

        line = reader.readLine();
    } catch (IOException e) {
        log.warn("error reading header", e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                log.warn("error closing file", e);
            }
        }
    }
    return line;

}


public static File multipartFileToFile(MultipartFile mFile) throws IOException {
    File convFile = File.createTempFile(mFile.getOriginalFilename(), ".tmp");
    convFile.createNewFile(); 
    org.apache.commons.io.IOUtils.copy(mFile.getInputStream(), new FileOutputStream(convFile));
    return convFile;
}

public static File multipartFileToFile(MultipartFile mFile, String suffix) throws IOException, IllegalStateException {
    File tmpFile = File.createTempFile(mFile.getOriginalFilename(), suffix);
    mFile.transferTo(tmpFile);

    return tmpFile;
}


public static byte[] readBytes(File file) throws IOException {
    return org.apache.commons.io.IOUtils.toByteArray(new FileInputStream(file), file.length());
}


public static void writeBytes(File file, byte[] data) throws IOException {
    org.apache.commons.io.IOUtils.write(data, new FileOutputStream(file));
}

} }

Update: I Googled the size of the bytearray and found that the source of the issue was not my code, but JGroups, which we were using for shared cache and ended up removing, so the problem went away. 更新:我搜索了字节数组的大小,发现问题的根源不是我的代码,而是我们用于共享缓存并最终删除的JGroups,因此问题消失了。 Here's the JGroups Issue in question: 这是有问题的JGroups问题:

https://issues.jboss.org/browse/JGRP-1117 https://issues.jboss.org/browse/JGRP-1117

It is nearly impossible to give a clear answer since you did not provide any useful information such as code. 由于您没有提供任何有用的信息(例如代码),因此几乎不可能给出明确的答案。

Java's garbage collector will eventually free memory when there are no references to it. 当没有引用时,Java的垃圾收集器最终将释放内存。 Try setting the array equal to null and make sure there are no functions, classes, or threads that are maintaining a reference in some way to unwanted memory. 尝试将数组设置为null,并确保没有函数,类或线程以某种方式维护对有害内存的引用。

尝试使用JVisualVM跟踪堆问题来自哪个类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM