iPhone 초보자 여기서는 피아노 마스터라는 간단한 음악 iPhone 응용 프로그램을 만들고 있는데,이 버튼을 클릭하면 소리가납니다.Obj-C iPhone : 메모리 관리
MusicViewController.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "PianoMasterAppDelegate.h"
@interface MusicViewController : UIViewController
<AVAudioPlayerDelegate> {}
- (IBAction)buttonClick:(id)sender;
@end
MusicViewController.m
#import "MusicViewController.h"
@implementation MusicViewController
- (IBAction)buttonClick:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Piano1" ofType:@"wav"];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path error:NULL];
theAudio.delegate = self;
[theAudio play];
}
버튼을 클릭 할 때 소리가 재생하지만, 매번 버튼을 클릭하면, A : 여기
내 코드입니다 새로운 AVAudioPlayer가 생성되면,이 메모리 문제를 효율적으로 관리하는 방법에 대한 가장 좋은 아이디어는 무엇입니까? MusicViewController에 대한 AVAudioPlayer의 인스턴스를 만들고이를 사용하려고 생각했지만 매번 새로운 AVAudioPlayer를 계속 할당하면 여전히 메모리 문제가 발생합니다 ... 도움이됩니다. 감사합니다.
버튼을 눌렀을 때 소리가 나지 않습니다. – user544359