Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clean up memory of a song in order to load the next one #76

Open
bigboss97 opened this issue Dec 19, 2022 · 3 comments
Open

How to clean up memory of a song in order to load the next one #76

bigboss97 opened this issue Dec 19, 2022 · 3 comments
Labels

Comments

@bigboss97
Copy link

I'm using Processing 4.1.1 in Android mode. I've downloaded the latest library from here and it works much better than the built-in one. Now I can open larger song and run it in correct speed. Thanks for the fix.

I'm currently facing an issue. I can't load next song because it runs out of memory. I tried to use removeFromCache(), assign null to my SoundFile and do System.gc(). Nothing helped.

My question, is there a way to force a memory release before I create the next SoundFile?

@kevinstadler
Copy link
Collaborator

Thanks for your report, could you maybe try downloading this library test build (just extract it into your Arduino/libraries folder) and make sure you explicitly call firstfile.stop() before all of your other garbage collection steps and let me know if that helps? The same gc issue is what underlies #74 so it would be great to get some grip on this...

@bigboss97
Copy link
Author

bigboss97 commented Dec 21, 2022

Thanks for your quick response. I've created following test sketch and it worked great:

import android.os.Environment;
import processing.sound.*;

final String androidRoot= new String( Environment.getExternalStorageDirectory().getAbsolutePath());
SoundFile music;
String song1= androidRoot+"/myHome/Music/English/Beat it - Michael Jackson.mp3";
String song2= androidRoot+"/myHome/Music/English/Beep - The Pussycat Dolls.mp3";


void setup() {
  while( true) {
    println("Load 1");
    music= new SoundFile( this, song1);
    music.play();
    println("Playing 1");
    delay(5000);
    
    music.stop();
    music.removeFromCache();
    music= null;
    println("Cleaned 1");
    
    println("Load 2");
    music= new SoundFile( this, song2);
    music.play();
    println("Playing 2");
    delay(5000);
    
    music.stop();
    music.removeFromCache();
    music= null;
    println("Cleaned 2");
  }
}

Unfortunately, it's still crashing in my program. I guess it's because of the variable scope. I use the SoundFile in a class. Maybe it doesn't get cleaned up as long as the object is still around. I'll work around this and use a global variable.

@trackme518
Copy link

Hi,
I have: similar issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants