Conservation of memory.

edited December 2017 in Library Questions

So I've created this audio sampler that holds sounds in groups. I designed if first with just one group to get the basics working. Once I added the rest which includes hundreds of audio files I, understandably, got an out of memory message upon opening the app.

I tried to fix this by only loading the sounds needed. i.e. I moved the "class= new Class();" parts from setup into the code for the buttons that switch groups. Now my app opens and I don't get a memory error... until I choose a group.

What gives?

Is this because I still declared the object before setup? ( Class class;)

I need help figuring out conservation of memory. How do I load the sounds only when I need them?

Answers

  • Before loading new 1s, you're gonna need to get rid of old 1s 1st! 8-|

  • Ok but that doesn't explain why the app crashes the first time I press a button.

    I moved the "class= new Class();" parts and deleted them from setup. Where do I put "Class class;" because if I put it that in the button function with class= new Class(); I get " the value of local variable Class class; is not used".

  • How can I un-load a class?

  • edited December 2017 Answer ✓

    B/c you're claiming hardware resources, in this particular case sounds, "un-loading" classes aren't enough. You've gotta get rid of the borrowed hardware resource itself! =;

    Check whether the audio library you're relying on got some dispose(), stop() or close() method. L-)

  • An mvce would help here a lot.

    Kf

Sign In or Register to comment.