On 8 mei, 17:51, Knute Johnson <nos...@rabbitbrush.frazmtn.com> wrote:
Erik wrote:
I have a problem with the ImageIO.read(new File(...)); method. When I
call this method and it reads an image,
but it is not stored in a BufferedImage (or something else), it still
consumes memory. So when only reading
a image and not storing the results, the image is still kept inside
the memory. Also forcing to garbage collect does
not help. Does anyone knows how to release (flush) the ImageIO memory?
Erik
Are you sure that it is out of scope when you try to garbage collect it?
Just for my curiosity, why would you read an image file and not keep a
reference?
--
Knute Johnson
email s/nospam/linux/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
:) No, I do want to keep a reference, but I tried to Isolate the
memory problem.
When I run this code and I load 2 JPEG images (1.88 MB each), the
program uses 43 MB of
my memory. Why doesn't the memory get released?
Here is some of my code (where I load the images):
/**
*
*/
package thumbnail;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* @author Erik Gast
*
*/
public class Thumbnail {
private Image smallThumbnail = null;
private Image normalThumbnail = null;
public Thumbnail(File imageFile, int fileID){
try {
ImageIO.setUseCache(false);
ImageIO.read(imageFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Image getSmallThumbnail(){
return smallThumbnail;
}
public Image getNormalThumbnail(){
return normalThumbnail;
}
public int getWidthNormalThumbnail(ImageObserver obs){
return normalThumbnail.getWidth(obs);
}
public int getHeightNormalThumbnail(ImageObserver obs){
return normalThumbnail.getHeight(obs);
}
public int getWidthSmallThumbnail(ImageObserver obs){
return smallThumbnail.getWidth(obs);
}
public int getHeightSmallThumbnail(ImageObserver obs){
return smallThumbnail.getHeight(obs);
}
}
When you read a file with ImageIO.read() it creates a BufferedImage. If
bigger when stored as a BufferedImage. Assuming they are color images
using a normal ColorSpace then they could take 4 bytes per pixel. If
your images are 2000x2000 pixels you are looking at 16MB. Big images
eat a lot of memory.
code. Why don't you try making an SSCCE that demonstrates your problem.