AvAudioPlayer 内存问题 audiotoolbox 32kb
我面临内存管理问题。在内存分配中,每次页面加载时都会增加 32kb,并且不会释放内存。一段时间后,当总内存达到 3 mb 时,它会崩溃为 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;
}
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 memory 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码存在许多问题:
-dealloc
末尾调用[super dealloc]
。-dealloc
中释放 soundFileURL。[appSoundPlayer release]
或self.appSoundPlayer = nil
,而不是同时使用两者。我强烈建议您阅读内存管理编程指南 http: //developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
There are numerous issues with your code:
[super dealloc]
at the end of-dealloc
.-dealloc
.[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