Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-16-2009, 09:55 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Johanovski is on a distinguished road
Default Trouble with memory leaks!

Hi all!

I'm having a problem with my app... I've been tracing memory leaks and solving them as I've found, but now I'm really stuck with it... I'll explain you what I'm doing and what is going wrong:

I've created a class called "Audio". This class have a property called "player" wich is a pointer to an AVAudioPlayer object:
************************************************** *************
interface Audio : NSObject {
NSString* label;
NSString* fileName;
NSString* fileType;
NSString* filePath;
NSURL* fileUrl;

AVAudioPlayer* player;
}
************************************************** *************

When this class inits calls it's own init method, wich is:
************************************************** *************
- (id)initAudio
{
[self init];

player = [[AVAudioPlayer alloc] init];

return self;
}
************************************************** *************

Then, another object called "Mosca" has a property wich is a pointer array to Audio objects, and Mosca's inits method has the following code:
************************************************** *************
(...)
for (int i=0; i<2; i++) {
sons[i] = [[Audio alloc] initAudio];
}
(...)
************************************************** *************

Everythings works fine, but when I try to release the objects the program gives me an EXC_BAD_ACCESS error near the [AVAudioPlayer release] method, and the way it gets there is the following:
************************************************** *************
// Mosca deallocation method
- (void) dealloc
{
//NSLog(@"dealloc mosca%d",_id);

for (int j=0; j<6; j++) {
[textures[j][0] release];
[textures[j][1] release];
[textures[j][2] release];
}

for (int i=0; i<2; i++) {
[sons[i] release];
}

[super dealloc];
}
--------------------------------------------------------------------------
// Audio's deallocation method:
- (void) dealloc
{
//NSLog(@"dealloc audio");

[label release];
[fileName release];
[fileType release];
[filePath release];
[fileUrl release];

[player release];

[super dealloc];
}
************************************************** *************
And then AVAudioPlayer has it's own deallocation method (wich is unaccessible for me because AVAudioPlayer is a part of the AVFoundation framework).

If i comment, for example, the [player release] command from the Audio deallocation method or the [sons[i] release] command from the Mosca deallocation method the program works fine and doesn't throw the EXC_BAD_ACCESS method, but then Instruments finds some leaks, all of them relating the initAudio method and pointing the [[AVAudioPlayer alloc] init] command.

Does anybody knows what can be happening? I'm really stuck with it...

Thanks in advance!
Johanovski is offline   Reply With Quote
Old 11-16-2009, 10:12 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

The problem may be outside of the code you have posted. Check all accesses to the player in an Audio object, and see if someone else is releasing player.

Also, you didn't mention whether player is a retained property of Audio, or just an instance variable.

Robert Scott
Ypsilanti, Michigan
RLScott is offline   Reply With Quote
Old 11-16-2009, 12:23 PM   #3 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

When you create the AVAudioPlayer, you need to tell it what sound to use with initWithContentsOfURL:error: or initWithData:error: . You can't init the player and then change the sound file later. Do you cane another line where you init the player with the sound name? Post that part too. It's probably the cause of the leak.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, leak, memory leaks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 343
13 members and 330 guests
akacaj, alexP, ClerurcifeDer, Duncan C, givensur, glenn_sayers, GraffitiCircus, guusleijsten, JmayLive, NetGuru, Paul Slocum, Punkjumper, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:44 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0