File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes OutOfMemory exception on MAC but not on win & linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "OutOfMemory exception on MAC but not on win & linux" Watch "OutOfMemory exception on MAC but not on win & linux" New topic
Author

OutOfMemory exception on MAC but not on win & linux

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi all;

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 ?

thanking you much.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Thank you ulf for reply;

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.

can some one help ?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello othman El Moulat,


Use Jconsole to verify the memory usage of your application. Check the memory input arguments of your application.

Typicall, on windows machine, the values will be,

-Xms40m
-Xmx256m

Ofcourse, you can alter and play.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

No Joe, i have tested my applet mith his same large tif file and it worked fine on win & linux and the file was downloaded correctly.

I think the problem is related to mac java settings ....
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

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 ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

So is your applet a signed applet, and it save this file to disk? If so, just make a smaller buffer and save it a chunk at a time.


[Jess in Action][AskingGoodQuestions]
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

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.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

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.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Thank you joe and all other guys that helped me solving this issue.

I just have another question not related to that:

I want to know which operating system my applet is running under. i specially want to be able to know if the OS is mac. how to do that ?
thanks.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

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.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

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.

No i won't do that . i have solved previous problem by simply setting buffer to 100kb and it worked fine.

Ineed to checkif my applet is runnin on mac to do some other GUI work. is this case what does System.getProperty("os.name") returns in case of mac ?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

I don't have a mac either. We do, however, have the Mac OS Forum. Perhaps they can help you.
 
jQuery in Action, 2nd edition
 
subject: OutOfMemory exception on MAC but not on win & linux
 
Similar Threads
OutOfMemory Error
is it possible to process a 500MB zipfile in java?
OutOfMemory
outOfMemory
OutOfMemory