什么时候使用Image.flush()安全(或强制)? [英] When is it safe (or mandatory) to use Image.flush()?

查看:2537
本文介绍了什么时候使用Image.flush()安全(或强制)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用Java(和Java本身)提供图像和缓冲图像的第一步,我对flush()方法有点困惑,我的问题很简单:什么时候安全甚至是强制刷新代码中的图像?

I've been giving my first steps with images and buffered images in Java (and Java itself) and I'm a little confused about the flush() method, and My question is quite simple: When is it safe or even mandatory to flush an image in the code?

做一些测试看起来像Image.flush()没有做任何事情,但BufferedImage.flush()给出一些随机的结果(有时一些内存似乎被释放),但我用来绘制它的组件停止在它的背景上绘制它。

Doing some tests it looks like Image.flush() doesn't do anything, but BufferedImage.flush() gives some random results (sometimes some memory seems to be freed), but the component I use to paint it stops painting it on it's background.

所以我应该使用Image.flush( )或BufferedImage.flush()或者是我必须让JVM自己做的事情,或者可能是在对象的finalize()方法中做的事情?

So should I ever use Image.flush() or BufferedImage.flush() or is that something that I have to let the JVM do on it's own, or maybe do it in the finalize() method of an object?

我真的无法理解......

I really can't figure it out...

推荐答案

你永远不需要打电话给同花顺(),除非你想释放内存。它基本上只是作为对象的暗示说,嘿,现在继续删除所有后备内存缓冲区,而不是等待垃圾收集来照顾你。它可以是一个有用的性能优化,但它永远不需要调用。

You never NEED to call flush(), unless you want to free up memory. It basically just serves as a hint to the object to say, "Hey, go ahead and remove all your backing memory buffers now, instead of waiting for garbage collection to take care of you." It can be a useful performance optimization but it's never necessary to call.

根据Java文档,调用 flush()应该让图像处于可以根据需要重建自身的状态,但显然你遇到了不是这种情况的问题。基本上,除非您确定不再需要图像,否则不要调用 flush()

According to the Java docs, calling flush() should leave the image in a state where it can reconstruct itself as necessary, but obviously you're running into issues where that isn't the case. Basically, don't call flush() unless you're sure you no longer need the image.

这篇关于什么时候使用Image.flush()安全(或强制)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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