Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you completely remove and release memory of an OpenAL sound file?
    primarykey
    data
    text
    <p>I have a small level based iPhone app. I need to load and release sound files for each level. Everything works fine with my openAL SoundManager except releasing sounds.</p> <p>At first, when I remove a sound, it seems to do what it is meant to do – it removes the sound and I can’t access it again unless I reload it. BUT, when I test my apps dealloc’s with ‘Instruments’ it doesn’t show any deallocation. It doesn’t seem to free up the memory. So, when you move from level to level, it doesn't take long for the memory to run out and the app to crash.</p> <p>I get this error in console:</p> <blockquote> <p>Program received signal: “0”. warning: check_safe_call: could not restore current frame kill quit</p> </blockquote> <p>This is how I load the sounds -</p> <pre><code>- (void)loadSoundWithKey:(NSString*)aSoundKey fileName:(NSString*)aFileName fileExt:(NSString*)aFileExt { // Check to make sure that a sound with the same key does not already exist NSNumber *numVal = [soundLibrary objectForKey:aSoundKey]; // If the key is found log it and finish if(numVal != nil) { NSLog(@"WARNING - SoundManager: Sound key '%@' already exists.", aSoundKey); return; } NSUInteger bufferID; // Generate a buffer within OpenAL for this sound alGenBuffers(1, &amp;bufferID); // Set up the variables which are going to be used to hold the format // size and frequency of the sound file we are loading ALenum error = AL_NO_ERROR; ALenum format; ALsizei size; ALsizei freq; ALvoid *data; NSBundle *bundle = [NSBundle mainBundle]; // Get the audio data from the file which has been passed in CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:aFileName ofType:aFileExt]] retain]; if (fileURL) { data = MyGetOpenALAudioData(fileURL, &amp;size, &amp;format, &amp;freq); CFRelease(fileURL); if((error = alGetError()) != AL_NO_ERROR) { NSLog(@"ERROR - SoundManager: Error loading sound: %x\n", error); exit(1); } // Use the static buffer data API alBufferDataStaticProc(bufferID, format, data, size, freq); if((error = alGetError()) != AL_NO_ERROR) { NSLog(@"ERROR - SoundManager: Error attaching audio to buffer: %x\n", error); } } else { NSLog(@"ERROR - SoundManager: Could not find file '%@.%@'", aFileName, aFileExt); data = NULL; } // Place the buffer ID into the sound library against |aSoundKey| [soundLibrary setObject:[NSNumber numberWithUnsignedInt:bufferID] forKey:aSoundKey]; if(DEBUG) NSLog(@"INFO - SoundManager: Loaded sound with key '%@' into buffer '%d'", aSoundKey, bufferID); </code></pre> <p>}</p> <p>And this is how I am trying to remove/release. But it still seems to retain the memory of the sound file -</p> <pre><code>- (void)removeSoundWithKey:(NSString*)aSoundKey { // Find the buffer which has been linked to the sound key provided NSNumber *numVal = [soundLibrary objectForKey:aSoundKey]; // If the key is not found log it and finish if(numVal == nil) { NSLog(@"WARNING - SoundManager: No sound with key '%@' was found so cannot be removed", aSoundKey); return; } // Get the buffer number form the sound library so that the sound buffer can be released NSUInteger bufferID = [numVal unsignedIntValue]; alDeleteBuffers(1, &amp;bufferID); [soundLibrary removeObjectForKey:aSoundKey]; if(DEBUG) NSLog(@"INFO - SoundManager: Removed sound with key '%@'", aSoundKey); </code></pre> <p>}</p> <p>Can anyone think of away to completely remove every trace of my sound file (with the ability to load it again)?</p> <p>Thank you very much!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload