AvAudioPlayer memory issue audiotoolbox 32kb
i am facing the memory management issue. in the memory allocation every time it increases 32kb when the page load and it does not release the memory .and after some time when the total m开发者_StackOverflow社区emory reach to 3 mb it crashes in 3mb 1 mb is only for audiotoolbox malloc. here's my code please help me
in .h file:-
AVAudioPlayerDelegate
AVAudioPlayer *appSoundPlayer;
NSURL *soundFileURL;
@property (retain) AVAudioPlayer *appSoundPlayer;
@property (nonatomic, retain) NSURL *soundFileURL;
- .m file
@synthesize appSoundPlayer;
@synthesize soundFileURL;
-(void)viewdidload
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Page_flip"
ofType:@"mp3"];
NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
self.soundFileURL = newURL;
[newURL release];
NSLog(@"**** We are now at cover page ****");
[super viewDidLoad];
}
#pragma mark -
#pragma mark read to me
-(void) readtome :(id) Sender
{
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil];
self.appSoundPlayer = newPlayer;
[newPlayer release];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[appSoundPlayer play];
}
- (void) dealloc
{
[appSoundPlayer release];
self.appSoundPlayer = nil;
}
There are numerous issues with your code:
- You're not calling
[super dealloc]
at the end of-dealloc
. - You're not releasing soundFileURL in
-dealloc
. - The method names should be camel case (viewDidLoad not viewdidload).
- Use either
[appSoundPlayer release]
orself.appSoundPlayer = nil
, not both.
I highly recommend you read the memory management programming guide http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
精彩评论