0
不知道這是一個模擬器的問題,或者我失去了一些東西,下面的代碼給我一個內存泄漏,雖然音頻是在dealloc中發佈的。我正在播放.wav文件,並且聲音將根據整數的值而改變。該應用運行確定,但我whwn測試此在xcode中AVAudioPlayer導致內存泄漏
任何建議非常感謝16位泄漏被判:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface Water : UIViewController
<AVAudioPlayerDelegate>
{
}
@property (nonatomic,retain) AVAudioPlayer *theAudio;
-(IBAction) goButMenu: (id) sender;
-(IBAction) goDrinkMenu: (id) sender;
-(IBAction) playwater;
@end
@implementation Water
@synthesize theAudio;
-(IBAction) goDrinkMenu: (id) sender{
ButDrinkMenu *butdrinkmenu1 = [[ButDrinkMenu alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:butdrinkmenu1 animated:YES];
}
-(void) viewDidLoad {
if (BoyOrGirl == 1) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Applause" ofType:@"wav"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
else {
NSString *path = [[NSBundle mainBundle] pathForResource:@"bongo" ofType:@"wav"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
}
-(IBAction) playwater{
if (BoyOrGirl == 1) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Applause" ofType:@"wav"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
else {
NSString *path = [[NSBundle mainBundle] pathForResource:@"bongo" ofType:@"wav"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
}
謝謝你,我做了一個快速測試,這段代碼解決了泄漏問題,我需要做更多的測試,但看起來不錯。乾杯。 – TJ15
太棒了!如果答案有效,請選擇已接受的答案。 – isaac