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
Post a Comment