AvAudioPlayer 内存问题 audiotoolbox 32kb

发布于 2024-11-04 17:34:54 字数 1309 浏览 1 评论 0原文

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

}

i am facing the memory management issue. in the memory allocation every time it increases 32kb when the page load and it does not release the memory .and after some time when the total memory reach to 3 mb it crashes in 3mb 1 mb is only for audiotoolbox malloc. here's my code please help me

in .h file:-

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;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白鸥掠海 2024-11-11 17:34:54

您的代码存在许多问题:

  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

There are numerous issues with your code:

  1. You're not calling [super dealloc] at the end of -dealloc.
  2. You're not releasing soundFileURL in -dealloc.
  3. The method names should be camel case (viewDidLoad not viewdidload).
  4. Use either [appSoundPlayer release] or self.appSoundPlayer = nil, not both.

I highly recommend you read the memory management programming guide http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文