ofSoundPlayer memory leak

Hi!

I’am having troubles with memory leaks the ofSoundplayer. My program loads different sounds into the same ofSoundPlayer instance over time. In my activity monitor (OSX) i can see the the memory increasing constantly.

The sounds witch are being loaded is mp3 from 500kb to 39mb. Does anyone know what is wrong?

I have pasted the code below.

Thanks for any help!

  
  
  
void poexTapeWiiRemote::updateSound(){  
    newSound = ptt->getSoundUnderPoint(wiiPoint);  
      
    soundPosition = ptt->getRelativeSoundPosition(wiiPoint);  
    if(newSound != NULL){  
        currentSound = newSound;  
        newSoundURL = newSound->soundURL;   
    }  
    else{  
        newSoundURL = "no sound";  
    }  
      
       
      
    if(!isThreadRunning()){  
        if(lock()){  
            startThread(true, false);  
        }  
    }  
}  
void poexTapeWiiRemote::threadedFunction(){  
    if(currentSound != NULL){  
          
        //if(soundPlayer.getURL() != newSoundURL){  
  
            soundPlayer.loadSound(newSoundURL, true);  
        //}  
    }  
      
    if(soundPlayer.getIsPlaying() != true  && buttonPressed){  
		soundPlayer.play();  
	}  
      
    if(buttonPressed){  
        soundPlayer.setPosition(soundPosition);  
    }  
	  
	if(currentSound == NULL || buttonPressed == false){  
           
		soundPlayer.stop();  
	}  
  
	ofSleepMillis(10);  
	stopThread(true);  
	unlock();  
	  
	  
}  
  

I’ve the same problem. Even if I manually unload the file, I still get memory leaks.

Tested on OSX 10.6, 10.8, 10.10 - OF 0.8.3

Any suggestion?

thanks!!!

Can you share the sound-related code you’re using, @Paolo?

I’ve solved the problem by creating a list of pointers to ofSoundPlayer and loading all the audio files (with streaming enabled) in the setup() method. As it suggested in the forum, I used a list of pointers to ofSoundPlayer rather then a list of objects, because in the second way I wasn’t able to change from one sound to the other and I guessed it was caused by something shared between the sound objects.

vector <ofSoundPlayer *> playersList;

It looks a little strange, that there is no documentation about how to load and play a list of sounds, but maybe I didn’t search enough.

Anyway this is a simplified version of the previous code, in order to replicate the problem I had before

class psAudio {
                    
private:
                	
	float   volume;
	bool    loop;
               
	vector <string> audioList;
	ofDirectory dir;
                        
	ofSoundPlayer player;
                               
	int index;
	int prevIndex;
                       
	void loadSounds();
                      
public:
                    
	// other stuff here
                    
};
// call this in the update() method                
void psAudio::loadSounds() {
                    
	if (index >= 0 && index < audioList.size()) {
                       
		// loadSound should unload the previous sound and 
		// release memory but from XCode-Instruments finds leaks
                        
		player.loadSound(audioList[index], true); 
		player.play();
		prevIndex = index;
                        
	} 
}