我正面临内存管理问题。在内存分配中,每当页面加载时它增加32kb并且它不释放内存。并且在总内存达到3mb后一段时间内它崩溃3mb 1 mb仅用于audiotoolbox malloc。这是我的代码,请帮帮我
在.h文件中: -
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;
}
答案 0 :(得分:1)
您的代码存在许多问题:
[super dealloc]
结束时致电-dealloc
。-dealloc
发布soundFileURL。[appSoundPlayer release]
或self.appSoundPlayer = nil
,而不是两者。我强烈建议您阅读内存管理编程指南http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html