【发布时间】:2011-04-29 05:25:56
【问题描述】:
单击播放按钮时出现内存泄漏....
我正在使用“运行和性能工具”下的“泄漏”工具进行测试....在模拟器上
当我第一次点击播放按钮时,我得到了泄漏.....
这是我的代码....
-(IBAction)play
{
[self setPlayer];
[self playme];
}
-(IBAction)stop
{
[self stopme];
[self releasePlayer];
}
-(void)setPlayer
{
NSURL *file = [[NSURL alloc] initFileURLWithPath:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"shut up.mp3"]];
NSError *err = nil;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:&err];
[file release];
player.numberOfLoops = -1;
[player prepareToPlay];
player.volume=1.0;
}
-(void)playme
{
if (!isPlaying)
{
[player play];
isPlaying=YES;
}
}
-(void)stopme
{
if (isPlaying)
{
[player stop];
isPlaying=NO;
}
}
-(void)releasePlayer
{
if(!isPlaying)
{
[player release];
player=nil;
}
isPlaying=NO;
}
【问题讨论】:
-
你不是问了同样的问题吗?
标签: iphone memory-leaks avaudioplayer