2011-05-02 4 views
0

메모리 관리 문제가 있습니다. 메모리 할당 때마다 페이지로드 및 메모리를 해제하지 않습니다 때 32kb 증가합니다. 그리고 총 메모리가 3 메가 바이트에 도달하면 얼마 후 그것은 1MB의 audiotoolbox malloc에만 충돌합니다. 여기 .H 파일에 나에게AvAudioPlayer 메모리 문제 audiotoolbox 32kb

도와주세요 내 코드입니다 : -

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; 

} 

답변

1

코드에 많은 문제가 있습니다

  1. 당신은 -dealloc의 끝에 [super dealloc]를 호출하지 않는가.
  2. -dealloc에 soundFileURL을 출시하지 않습니다.
  3. 메소드 이름은 낙타의 경우 여야합니다 (viewDidLoad는 viewdidload가 아님).
  4. [appSoundPlayer release] 또는 self.appSoundPlayer = nil 중 하나만 사용하십시오.

내가보기 엔 당신은 메모리 관리 프로그래밍 가이드를 읽어 보는 것이 좋습니다 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html