I developped an applet that deals with unlimited size files downloads. the applet works fine for small/medium file sizes. I tested it with a large tif file (58MB) : on windows and linux boxes the download just works fine.. the problem raised when i tried downloading this tif 58MB on a MAC OS 10 box. the appplet throws a : OutOfMemory exception java heap size.
what could be the cause of this error ? and why it only raised on MAC and not on winxp/linux ?
On Windows and Linux you're probably using the Sun JVM, which is different from the Apple JVM. So it's no big surprise that they should have different memory usage characteristics. The more interesting question is: how can you change the default memory allocation for the plugin? I don't have a Mac in front of me, but on Windows you can do this in the Java Plugin control panel in the second tab ("Extended") under runtime parameters. [ September 13, 2006: Message edited by: Ulf Dittmer ]
Ping & DNS - updated with new look and Ping home screen widget
I just came to your same reasoning while i investigated the problem. i probably need to set the java heap size using some args like "-Xmx250m" right ? this problem was reported to me by a client that has tested my applet on his mac..and i don't have a mac to be able to investigate how to set java plugin params !
i don't know what to tell him or what to do cauze i don't have a mac under my hands.
Just speculating here, but maybe the guy on the mac is the only one who has attempted to download a large file. Have you tested your applet with very large files on other platforms? Are you by chance reading the entire file in before writing it out?
I decided to reexamine my code for memory leaks: here is the suspicious bit of code that might be the cause of memory overload :
i think the abyte0 array will be huge size if the file size is 58MB. is that the cause of my memory problem ? if this is the case how can i solve this ? the abyte0 array is where i'm writing the file. can you help please ?
thank you ernest, yes my applet is signed and it saves files to disk.
yes i will reduce the buffer size of the array to write to. but in this case if the size of file to download is biger than buffer how can i complete the download? can you explain more how to save file by chunks ? thanking you much.
Originally posted by othman El Moulat: i think the abyte0 array will be huge size if the file size is 58MB. is that the cause of my memory problem ?
That's exactly what I was thinking your problem was. Reading files in that manner doesn't scale well. I'll bet larger files (64Meg+) will fail in the other platforms as well as the default VM size for an applet is 64Megs. Have a look at this chapter in the Java Platform Performance book for some options for efficient IO.
The java.lang.System class contains that information. Look at the getProperties() method for the full list. I hope you aren't thinking about making different methods for downloading on different platforms. Your original code won't scale well no matter the platform.