Out of memory error (Sound problem?)


I think its playing sound that creates the problem, here is the error:

  at com.jsyn.data.FloatSample.allocate (Unknown Source)
  at com.jsyn.data.FloatSample.<init> (Unknown Source)
  at com.jsyn.data.FloatSample.<init> (Unknown Source)
  at com.jsyn.util.soundfile.AudioFileParser.makeSample (Unknown Source)
  at com.jsyn.util.soundfile.WAVEFileParser.finish (Unknown Source)
  at com.jsyn.util.soundfile.AudioFileParser.load (Unknown Source)
  at com.jsyn.util.soundfile.CustomSampleLoader.loadFloatSample (Unknown Source)
  at com.jsyn.util.SampleLoader.loadFloatSample (Unknown Source)
  at processing.sound.SoundFile.<init> (Unknown Source)
  at com.example.MyApp.setup (Unknown Source)
  at processing.core.PApplet.handleDraw (PApplet.java:1838)
  at processing.core.PSurfaceNone.callDraw (PSurfaceNone.java:476)
  at processing.core.PSurfaceNone$AnimationThread.run (PSurfaceNone.java:516)

I have checked that I only load the sounds in void setup and not void loop. It works on most devices but some devices crash when they open the app.
The program runs around 1000 lines of code so I’ll try to only include the sound related lines of code. If you need more of the code, I will provide additional code.

import processing.sound.*;

SoundFile point;
SoundFile backgroundMusic;
SoundFile engine;

void setup(){
  point = new SoundFile(this, "coin.wav");
  backgroundMusic = new SoundFile(this, "Stardrive.wav");
  engine = new SoundFile(this, "rocketEngine.wav");


void loop(){
  if(thing happens){ //If an X coordinate is smaller than 0

if(keyPressed){ //If w, a, s or d is pressed
  moving = 1;
  if (moving == 1){
    if (engine.isPlaying() == false) {
      if (soundIconOn == 1){

  if(button is pressed){ //Mouse pos is over a button and mouse is pressed
          if(musicIconOn == 0){

          if(backgroundMusic.isPlaying() == false){

        musicIconOn = 1;
      } else if (musicIconOn == 1){
        musicIconOn = 0;

void stop() {

void resume(){


@Banansplitt ===

  • looking at the error log it seems that you are right (problem with sounds loading)

  • but without knowing the size of these sounds it s difficult to test and help (better could be that you put somewhere these sounds for downloading them)

  • not all devices are crashing: which phones are crashing (OS,…)

  • anyway if the error is related to the sounds size you can try to load the sounds using an AsyncTask in on create()


The files are 47MB, 409KB and 15KB. So it would seem like its the 47MB file that’s crashing it? It crashes on android 6.0.
Maybe some devices aren’t powerful enough to run it? I used (almost) the same code to run the app on a Raspberry Pi (Linux) and it crashed there too.

Is this what you mean by AsyncTask? and if it is, it looks like you use it to download files when you open the app for the first time. Is that right?


@Bananasplitt ===

ok; in order to be sure try to put some little sound instead of the 47MB one: if it does not crah anymore you know who is the culprit! -As for the other point, yes, that is what i mean by AsyncTask and you can try to use it, though now, knowing that it s a really big file i am no sure that it will fit (because AsyncTask is supposed to run only some seconds, let us say 5 at max). If it does not work because of this limit there are other solutions, but begin with it.


@Bananasplitt I’m the author of the Sound library, I think the problem isn’t necessarily with loading the file but simply that the RAM of some of your devices isn’t big enough to store the large audio sample in memory (or at least the Android system appears to refuse to allocate the amount of memory required). Since the sound library only supports playing sounds stored in RAM, the only fix I can think of right now is to reduce the size of the large audio sample by reducing the sample rate of the WAV file, if that is an option for your application…

I’d be very interested to know under what circumstances exactly the RAM allocation fails, like which Raspberry and phone models were you using?

I’m glad people are using the library on Android, if there’s any other issues you’ve come across please let us know!


Thanks for letting me know. It is a Huawei P8 and a Raspberry Pi 3 B+. I have noticed that the app takes quite a bit of ram to run so that makes sense


You could try setting a large heap size in your manifest. This would double the allocated RAM for your app.


@shedMusic === that could be a good solution, though Android is strongly against large heap size which can generate many problems for the other apps… I think also that it is interesting in the case described by @Banansplitt that you add some method to verify that the Manifest tag about heap was really used (because many phones ignore it). Code (android but easy to adapt) for doing that:

Context ctx = getApplicationContext();

(ActivityManager)am =  ctx.getSystemService(Context.ACTIVITY_SERVICE);
int memoirebase=am.getMemoryClass();
int grossememoire= am.getLargeMemoryClass();