Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Out of Memory Error

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Out of Memory Error

    I'm making a Chain Rxn clone and after playing the game for a while it gives me this:

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at sun.audio.AudioStream.getData(AudioStream.java:90)
    at grid.Dot.playSound(Dot.java:314)
    at grid.Dot.explode(Dot.java:163)
    at grid.Grid.play(Grid.java:166)
    at grid.Grid.init(Grid.java:116)
    at chainrxnalpha.chainrxnalpha.main(chainrxnalpha.jav a:68))



    This is the method where the error is thrown:

    public void playSound(String soundFile) {
     
            try {
     
                SFX = new AudioStream(new FileInputStream("src/sounds/" + soundFile + ".wav"));
     
                MD = SFX.getData(); // this is where the error (in red above^^) is thrown
     
     
                once = new AudioDataStream(MD);
            } catch (IOException error) {
                System.out.println("File not found!");
            }
     
            MGP.start(once); // sometimes the error is thrown here depending on the frequency of sounds playing
     
            try {
                SFX.close();
            } catch (IOException error) {
                System.out.println("Closing error");
            }
     
            System.out.println("play sound " + soundFile);
     
        }

    I have deduced that the error has to do with the inefficiency of data being transferred, but should not Java have this stuff done automatically? Or is there a different way to play sound that I am unaware of?

    I have already tried to increase heap size with a Plist editor but I still get the same error at the same time.

    I am on an iMac and using Netbeans 6.7.1 (I get the same error on the school computers which are PCs).

    Ask me for more info if this is not clear. thankyooo


  2. #2
    Member
    Join Date
    May 2010
    Posts
    38
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Default Re: Out of Memory Error

    I think the problem is in "MD = SFX.getData();". From your code it seems that your reading the entire file into memory, a very very bad idea. See if there is a way to pass a stream object instead of the whole raw file.

  3. The Following User Says Thank You to Lord.Quackstar For This Useful Post:

    JavaPF (June 1st, 2010)

Similar Threads

  1. Out of memory work around for a java application (please help!)
    By javameanslife in forum Java Theory & Questions
    Replies: 5
    Last Post: January 22nd, 2010, 03:27 AM
  2. free memory of bufferedimage
    By mr_empty in forum Java SE APIs
    Replies: 2
    Last Post: January 19th, 2010, 05:14 AM
  3. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 04:26 AM
  4. Java memory management
    By trueacumen in forum Java Theory & Questions
    Replies: 5
    Last Post: August 12th, 2009, 02:40 AM
  5. Replies: 10
    Last Post: June 22nd, 2009, 07:45 AM