• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OutOfMemory exception on MAC but not on win & linux

 
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have a mac either. We do, however, have the Mac OS Forum. Perhaps they can help you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic