Java Images占用太多内存 [英] Java Images take up too much memory

查看:194
本文介绍了Java Images占用太多内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用大量图片的程序。
它从文件中加载了很多图像,并将它们存储起来,因此只加载一次。
它还会创建多个BufferedImages,大约400x400,其中不会超过10个。

I have a program that uses a lot of images. It loads alot of images from file, and stores them so they are only loaded once. It also creates multiple BufferedImages, about 400x400, there would be no more than 10 of these.

文件中的图像总数约为6MB。
每个BufferedImage应该是大约400x400x4 = 640KB。

The images from file total around 6MB. Each BufferedImage should be approx 400x400x4=640KB.

然而,内存使用量是500MB!

Yet, the memory usage is 500MB!

其中一些将用于该计划的其余部分,但我很确定这些图像占据了大部分空间。

Some of this will be for the rest of the program, but I'm pretty sure that the images are taking up most of the space.

有谁知道该怎么做这样做?
或BufferedImage的替代品,使用更少的内存?

Does anyone know what to do about this? Or an alternative to BufferedImage that uses less memory?

推荐答案

听起来像你的应用程序(不是库) )有内存泄漏。在第一种情况下,您应该尝试使用标准Java内存分析器来识别泄漏。

It sounds to me like your application (not the library) has a memory leak. In the first instance you should try to identify the leak using a standard Java memory profiler.

编辑

现在你已经确定有很多 BufferedImages 闲逛,你需要做的下一件事是找出它们仍然可以访问的原因。进行堆转储,查看一些实例,看看它们是如何连接到堆根的;请参阅 http://download.oracle.com/javase/ 6 / docs / technotes / guides / visualvm / heapdump.html

Now you've identified that there are lots of BufferedImages hanging around, the next thing you need to do is figure out why they are still reachable. Take a heap dump, look at some instances and see how they are connected to a heap root; see http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/heapdump.html

在做这类事情时,查看相关部分很有用。使用您最喜欢的Java IDE的Java源代码。

When doing this kind of stuff, it is useful to look at the relevant parts of the Java source code using your favorite Java IDE.

这篇关于Java Images占用太多内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆