Increase Applet Memory - IE issue

Hey guys,

i have a Java Applet, which handles displaying images.

Now the images being displayed are sometimes large in size. I have been increasing the maximum heap size for the applet (setting -Xmx260m) to handle up to this amount of memory, this works fine under IE for clients having around 1GB memory. In firefox case, i can go up to 650MB without any problems.

Under IE, the problem I am facing is when I try to increase the size beyond 300MB (for my 1GB machine), and under other machines, even above 150MB would cause problems (the problem being jre not being able to load). The result of my research lead to the fact that this is caused by IE-java issue not allowing large amounts of contiguous memory to be assigned to jvm.

So this seems to be a problem of IE-jvm, since it is working under Firefox. And the other issue is that we are not able to detect the amount of contiguous memory that can be available for the system before trying to load the java applet, and therefore unable to guess the highest value that can be assigned.

The real problem lies in the limitation that Internet Explorer is pausing on us when loading the applet.

One approach I am trying is to have some of the memory being used, whenever can be done, to be written into temp files on the client抯 system, instead of keeping them in memory. Yet due to the large sizes of the images, this might affect performance (some images come in the sizes of 2100x2100 bytes = 4 million bytes being read/written consuming therefore 800ms/400ms = 1.2 seconds, and if we抮e treating many images at the same time, performing this operation many times would affect the performance of the applet a lot)

Thanks guys,

[1729 byte] By [mcfarhat1a] at [2007-11-26 18:09:35]
# 1
What is the purpose of your applet?I think loading a full image into memory is a bad idea.You can at least compress the images in memory.
Rodney_McKaya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 2

Rodney,

thanks for the fast reply

the purpose of the applet is to display images, and allow manipulations of these images

i am loading the pixels of the image into an array of int, u have a suggestion of how to work on this, without additional load on the applet affecting performance? i did not understand quite well ur suggestion about loading compressed data of the image

Thanks a bunch

mcfarhat1a at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 3

It depends how you handle your images exactly.

Do you show the full image, or just a lowres?

Do you need to handle only one image at a time?

What kind of images do you work with? JPEG? TIFF?

For example you can compress the int array using gzip compression to save memory.

And just decompress it when you need to access the image data.

Message was edited by:

Rodney_McKay

Rodney_McKaya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 4

the images i am using are dicom images (medical type), which can contain either bitmap, or jpeg, or even jpeg2000 images

as for how i am displaying the images, i need to display the best quality possible, and the manipulations can occur anytime on the images

so what u r suggesting is to compress/decompress the int arrays all the time ?

mcfarhat1a at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 5

some images come in the sizes of 2100x2100 bytes = 4 million bytes

Are you getting confused between pixels and bytes?

If you are using an int array, 2100x2100 pixels equates to 2100x2100x4 bytes, ie 16Mb. And that's in addition to the same data used to store the actual Image, so chances are each of your images is using 32Mb.

Do you actually have to store multiple images at once? If you only need keep one in memory then your job becomes a lot easier.

What operations are you performing on the images? What's your actual flow of data?

300Mb of heap space should be unnecessary, frankly. I've managed to write usable applets which handle multiple 150dpi+ scans of A4 pages within the default 96Mb heap space.

itchyscratchya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 6

sorry about that, i meant 4 million pixels, around 16 MB memory

and yes, my applet needs to be able to display 25 images at the same time, with the capability of modifying the WW/WL (Width and Level - contrast/brightness), rotate, flip, and do all sorts of manipulations on the image

so yeah, i need to keep all the images being displayed in memory, especially that the user can select multiple images, and perform manipulations on them at more than one image at the same time(up to all images)

mcfarhat1a at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 7
That's fine.But this still doesn't mean you have to load the full image to memory.I'm working with tiffs that might take 500 MB in memory if loaded fully to memory.But this is not necessary, because the user can't see the whole image on screen anyway.
Rodney_McKaya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 8

i need to keep all the images being displayed in memory, especially that the user can select multiple images, and perform manipulations on them at more than one image at the same time(up to all images)

Couldn't you do that by selecting thumbnails and applying an operation to all the relevant images?

In this case there's no inherent requirement to hold all images at once: just process them in turn.

itchyscratchya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 9

Rodney,

the user needs to see the whole image, i guess this requires the whole image loaded into memory, especially if manipulations can be done to the image as a whole (all pixels will subdue changes)

itchyscratchy,

the way the applet is required (and implemented now), is for all multiple images to be displayed at the same time, and for manipulations to be peformed on them live. i don't know if i am successfully transferring the picture to you guys, but if i start loading/unloading items from/to memory (from/to file system), this would slow down my applet a lot

Thanks guys

mcfarhat1a at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 10
Taking a slightly different angle - if you're requiring huge heap sizes and access to the file system, would you be better off with a WebStart app than an applet?And, playing devil's advocate, how are you displaying 25 4Mpx images at the same time? :o)
itchyscratchya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...
# 11

How can you display a 2100x2100 image to the user?

AFAIK this screen resolution does not exist yet...

And I missed on of your previous replies.

Yes you can compress the byte array and decompress it every time you need to access the image data.

It will be much faster than accessing the disk, and will save a lot of memory.

Rodney_McKaya at 2007-7-9 5:41:35 > top of Java-index,Desktop,Core GUI APIs...