Home java Java Error java.lang.OutOfMemoryError: Java heap space

Java Error java.lang.OutOfMemoryError: Java heap space

Author

Date

Category

In general, I glued together all the music that I wanted to make in the background, and it turned out 315MB. I threw it into the project, and tried to start it with the help. But it didn’t work (Method code for playing music:

public static void play (URL url)
{
  clip = AudioSystem.getClip ();
  clip.open (AudioSystem.getAudioInputStream (url));
  clip.start ();
}

How do I fix this? I tried to entice my memory, but I got an error, either there was not enough memory, or something else. There are 2GB of RAM on your computer.


Answer 1, authority 100%

Try increasing the jvm heap size.
To do this, specify in the jvm arguments:

java -Xmx1024m -Xms256m

The Xmx parameter specifies the maximum size the heap will occupy, and Xms the initial size allocated for the heap.

If you are using IntelliJ Idea, then you can do it like this: select the launch configuration and write this line in the VM Options field (-Xmx1024m -Xms256m without java ).

In Eclipse: Run – & gt; Run configuration – & gt; arguments tab – & gt; VM arguments


Answer 2

As I understand, your music is stored in the RAM. P.s no one stores music in the RAM, there were always buffers in size (as indicated in the format of your file, for example, a bitrate of 128 kb). I think you will not be able to implement this with Clip, or put your music in a chtoli file.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions