Memory loading & unloading iPhone advice

hey all,

So at the moment my app is crashing due to too much stuff being loaded in memory.

For each scene/level of my app I have created a loader & unloader that gets called as you enter/exit a level.

I am using instances of ofImage then in the loader doing loadImage() and unloader just image.clear()

With the sounds I am using a std::map (as-mentioned-here) and in unload doing:

  
  
	map<string, ofSoundPlayer>::iterator it;  
    for(it = sounds.begin(); it != sounds.end(); ++it){  
        string name = it->first;  
		sounds[name].unloadSound();  
    }  
  

With the images, should I just be using loadImage() and clear(), or should I be doing something else?

With the sound, it current crashes on unloadSound(). Should I be doing something else instead, like destroying the object each time?

many thanks

Just a thought, but I wonder if it might be easier to ensure that encapsulated memory isn’t modified by using pointers in the map rather than ofSoundPlayer? I know that’s not the C++iest answer, but the SoundEngine_UnloadBackgroundMusicTrack() looks like:

  
	if (sBackgroundTrackMgr)  
	{  
		delete sBackgroundTrackMgr;  
		sBackgroundTrackMgr = NULL;  
	}  

and that call to delete might cause a crash. I can grab an iPhone from someone later and test it out if you’d like.

Do you think you need to completely destroy the instance of ofSoundPlayer? How much data/memory might the class take up once a sound has been unloaded?

cheers

I suppose so, b/c BackgroundTrackMgr can have quite a bit of stuff allocated and stored w/in it, if you snoop around in SoundEngine.cpp you’ll see what all it handles. Again, I really don’t know, I’m just wondering if the container might not be ensuring that the BackgroundTrackMgr is correctly deleted. Z Gage would probably have some better ideas. How many tracks are you loading into memory before you empty it?

On one scene I have 22 audio files. A combination of short background loops & shorter sound fx. How many can openAL have loaded at once?