AvAudioPlayer内存问题audiotoolbox 32kb

时间:2011-05-02 11:19:59

标签: iphone avaudioplayer

我正面临内存管理问题。在内存分配中,每当页面加载时它增加32kb并且它不释放内存。并且在总内存达到3mb后一段时间内它崩溃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;

}

1 个答案:

答案 0 :(得分:1)

您的代码存在许多问题:

  1. 您未在[super dealloc]结束时致电-dealloc
  2. 您没有在-dealloc发布soundFileURL。
  3. 方法名称应为camel case(viewDidLoad not viewdidload)。
  4. 使用[appSoundPlayer release]self.appSoundPlayer = nil,而不是两者。
  5. 我强烈建议您阅读内存管理编程指南http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html