开发者

AvAudioPlayer memory issue audiotoolbox 32kb

开发者 https://www.devze.com 2023-03-02 08:39 出处:网络
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 m开发者_StackOv

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 m开发者_StackOverflow社区emory 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;

}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号