Java Images占用太多内存

编程入门 行业动态 更新时间:2024-10-28 16:18:37
本文介绍了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 闲逛,你需要做的下一件事是找出它们仍然可以访问的原因。进行堆转储,查看一些实例,看看它们是如何连接到堆根的;请参阅 download.oracle/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 download.oracle/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占用太多内存

本文发布于:2023-05-27 01:50:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/275002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:太多   内存   Java   Images

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!