Skip to main content

[JAVA2D] Memory and images

3 replies [Last post]
Anonymous

Hi guys,

Conceptual question for you, if you don't mind.

Why is one able to load images up in various C/C++ image viewer
applications (for instance, Windows XP's ImageViewer application) and
use very little memory, but if you load the same image in a java
application you consume a substantial amount of memory?

I know you have to consider the overhead the JVM adds to the picture,
but I'm surprised that it seems to be so much. I end up getting
OutOfMemory exceptions for images I really don't expect to, and have to
up my JVM to well over 128MB heap space for most images.

Forgive me if this is a naive question, but I can't really see anything
in my application that seems to be causing this. Is C/C++ really that
much more efficient for imaging applications on the memory side?

Thanks for your help.
John

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nidel, Mike

John,

Can you tell us a bit more about your images? The format, tiling,
compression, size, etc.?

In my experience there is no inherent reason a Java app should be
a great deal slower or use a lot more memory than a native app.
However, there may be some difference with the readers that are
being used to decode the format in either case.

Have you tried running a memory profiler such as JProbe?

Mike

> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of John Wells
> Sent: Sunday, July 17, 2005 11:58 PM
> To: JAVA2D-INTEREST@JAVA.SUN.COM
> Subject: [JAVA2D] Memory and images
>
>
> Hi guys,
>
> Conceptual question for you, if you don't mind.
>
> Why is one able to load images up in various C/C++ image
> viewer applications (for instance, Windows XP's ImageViewer
> application) and use very little memory, but if you load the
> same image in a java application you consume a substantial
> amount of memory?
>
> I know you have to consider the overhead the JVM adds to the
> picture, but I'm surprised that it seems to be so much. I
> end up getting OutOfMemory exceptions for images I really
> don't expect to, and have to up my JVM to well over 128MB
> heap space for most images.
>
> Forgive me if this is a naive question, but I can't really
> see anything in my application that seems to be causing this.
> Is C/C++ really that much more efficient for imaging
> applications on the memory side?
>
> Thanks for your help.
> John
>
> ==============================================================
> =============
> To unsubscribe, send email to listserv@java.sun.com and
> include in the body of the message "signoff JAVA2D-INTEREST".
> For general help, send email to listserv@java.sun.com and
> include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Chet Haase

John,

Also, what release are you using? There was a major fix in
5.0 that eliminated some of the temporary images we used when
loading images through some mechanisms; these temporary images
tended to bloat the footprint way beyond what you could expect.

There may be some paths where we still do this; what methods are you
using to load the images? What images types are you loading?

Chet.

Nidel, Mike wrote:
> John,
>
> Can you tell us a bit more about your images? The format, tiling,
> compression, size, etc.?
>
> In my experience there is no inherent reason a Java app should be
> a great deal slower or use a lot more memory than a native app.
> However, there may be some difference with the readers that are
> being used to decode the format in either case.
>
> Have you tried running a memory profiler such as JProbe?
>
>
> Mike
>
>
>
>>-----Original Message-----
>>From: Discussion list for Java 2D API
>>[mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of John Wells
>>Sent: Sunday, July 17, 2005 11:58 PM
>>To: JAVA2D-INTEREST@JAVA.SUN.COM
>>Subject: [JAVA2D] Memory and images
>>
>>
>>Hi guys,
>>
>>Conceptual question for you, if you don't mind.
>>
>>Why is one able to load images up in various C/C++ image
>>viewer applications (for instance, Windows XP's ImageViewer
>>application) and use very little memory, but if you load the
>>same image in a java application you consume a substantial
>>amount of memory?
>>
>>I know you have to consider the overhead the JVM adds to the
>>picture, but I'm surprised that it seems to be so much. I
>>end up getting OutOfMemory exceptions for images I really
>>don't expect to, and have to up my JVM to well over 128MB
>>heap space for most images.
>>
>>Forgive me if this is a naive question, but I can't really
>>see anything in my application that seems to be causing this.
>> Is C/C++ really that much more efficient for imaging
>>applications on the memory side?
>>
>>Thanks for your help.
>>John
>>
>>==============================================================
>>=============
>>To unsubscribe, send email to listserv@java.sun.com and
>>include in the body of the message "signoff JAVA2D-INTEREST".
>> For general help, send email to listserv@java.sun.com and
>>include in the body of the message "help".
>>
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

John Wells

Chet Haase wrote:

> John,
>
> Also, what release are you using? There was a major fix in
> 5.0 that eliminated some of the temporary images we used when
> loading images through some mechanisms; these temporary images
> tended to bloat the footprint way beyond what you could expect.
>
> There may be some paths where we still do this; what methods are you
> using to load the images? What images types are you loading?

Guys,

Thanks for the reponses. I'll try to answer best I can (I'm an imaging
newbie, so still coming up to speed on some terminology...perhaps half
my problem? ):

I'm currently using JDK 1.4.2. with JAI 1_1_2_01. I will try to use JDK
1.5 and see if it makes a difference at all.

Regarding tiling, you've only led me to realize I have a lot to learn
:-). Average size of a grayscale TIFF is approximately 350 KB. Average
size of JPEG is around 150-200KB.

Regarding what I'm using to load the images, I'm simply using some
example code I found somewhere in the documentation. My application
only supports TIFFs and JPEGS. In the below code, DocImage is simply
BufferedImage extended with some extra metadata for my use:

public static DocImage readJPEG(File file) throws IOException {
BufferedImage image = null;
DocImage rImage = null;
image = ImageIO.read(file);
if (null!=image) {
rImage = DocImage.convertToDocImage(image);
rImage.setImageType("JPEG");
}
return rImage;
}

public static DocImage readTiff(File file) throws IOException {
BufferedImage image = null;
DocImage rImage = null;
FileSeekableStream stream = null;
stream = new FileSeekableStream(file);
ParameterBlock params = new ParameterBlock();
params.add(stream);
TIFFDecodeParam decodeParam = new TIFFDecodeParam();
decodeParam.setDecodePaletteAsShorts(true);
RenderedOp image1 = JAI.create("tiff", params);
image = image1.getAsBufferedImage();
if (null!=image) {
rImage = DocImage.convertToDocImage(image);
rImage.setImageType("TIFF");
}
return rImage;
}

Thanks for your help. If I can provide any further info that might help
you make sense of my problem, please let me know.

Thanks!
John

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".