iphone - AVAudioPlayer memory leaks -


i have method in exterior class gets called whenever charachter in game hits wall (about once every 5 seconds on average). dont understand it. thaught on top of memory management. everytime method called, small amount of memory leaked (malloc 38 or 42 bytes) keeps happening, , game freezes up. here code:

-(void)playboing {     int x = (arc4random()%3)+1;     nsstring *path = [nsstring stringwithformat:@"/boing_0%i.aif", x];      nsstring* resourcepath = [[nsbundle mainbundle] resourcepath];     resourcepath = [resourcepath stringbyappendingstring:path];      if (boing != nil) {         boing = nil;         boing.delegate = nil;         [boing release];     }     boing = [[avaudioplayer alloc] initwithcontentsofurl:              [nsurl fileurlwithpath:resourcepath] error:nil];      boing.delegate = self;     boing.volume = 1;     [boing play]; } 

of course, it's lead memory leak

first said, boing nil (but memory not deallocated, leaked), trying send release message nil. should this:

[boing release]; boing = [[avaudioplayer alloc] initwithcontentsofurl:              [nsurl fileurlwithpath:resourcepath] error:nil]; 

no need check boing nil before releasing, because sending message nil nothing


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -