Releasing
I am lost,:confused: I have 4 views and in each view I am playing 4 sounds in each one. Here is the code for the .H file:
here is the code for the .M file:
So my problem is, when I call the dealloc method in the 3rd view it crashes, so I decided to check the retain count for each (CFURLRef) and the retain count from the 1st view to the 2nd view is (2), but when when I go to the 3rd view the retain count drops to (0) what am I doing wrong?
P.S. The dealloc method is getting called on each view. Do the CFURLRef's get automatically deallocated for you.
Code:
SystemSoundID Geese;
SystemSoundID Donkey;
SystemSoundID Goat;
SystemSoundID DogBark;
CFURLRef filePath;
CFURLRef filePath2;
CFURLRef filePath3;
CFURLRef filePath4;
@property (readwrite) CFURLRef filePath;
@property (readwrite) CFURLRef filePath2;
@property (readwrite) CFURLRef filePath3;
@property (readwrite) CFURLRef filePath4;
@property (readonly) SystemSoundID Geese;
@property (readonly) SystemSoundID Donkey;
@property (readonly) SystemSoundID Goat;
@property (readonly) SystemSoundID DogBark;Code:
// sound effect is created
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();
filePath = CFBundleCopyResourceURL ( mainBundle, CFSTR ("DogBark"), CFSTR ("aiff"),NULL);
AudioServicesCreateSystemSoundID ( filePath, &DogBark );
// sound effect is created
filePath2 = CFBundleCopyResourceURL ( mainBundle, CFSTR ("Donkey"), CFSTR ("aiff"),NULL);
AudioServicesCreateSystemSoundID ( filePath2, &Donkey );
// sound effect is created
filePath3 = CFBundleCopyResourceURL ( mainBundle, CFSTR ("Geese"), CFSTR ("aiff"),NULL);
AudioServicesCreateSystemSoundID ( filePath3, &Geese );
// sound effect is created
filePath4 = CFBundleCopyResourceURL ( mainBundle, CFSTR ("Goat"), CFSTR ("aiff"),NULL);
AudioServicesCreateSystemSoundID ( filePath4, &Goat );
(Dealloc method)
AudioServicesDisposeSystemSoundID(Geese);
AudioServicesDisposeSystemSoundID(Donkey);
AudioServicesDisposeSystemSoundID(Goat);
AudioServicesDisposeSystemSoundID(DogBark);
CFRelease(filePath);
CFRelease(filePath2);
CFRelease(filePath3);
CFRelease(filePath4);P.S. The dealloc method is getting called on each view. Do the CFURLRef's get automatically deallocated for you.
Can you try to build and analyze with CLang? If you're messing up with a retain/release, then it might catch it.
I'm not familiar with AudioServices, but I would imagine that you'd want to release instead of dealloc those sounds.
CFURLRef will not be freed automatically if you fail to release it yourself. (IIRC, the garbage collector might help you here, but if you're not using it, then you're on your own).
I'm not familiar with AudioServices, but I would imagine that you'd want to release instead of dealloc those sounds.
CFURLRef will not be freed automatically if you fail to release it yourself. (IIRC, the garbage collector might help you here, but if you're not using it, then you're on your own).
What do you mean by (IIRC, the garbage collector)
Why are your four file paths stored into instance variables which have matching properties? Are you using them anywhere else except for when you load the sound?
Quote:So my problem is, when I call the dealloc method in the 3rd viewWhat do you mean you call the dealloc method? You shouldn't be calling dealloc.
Quote:it crashesCrashes with what exception? Crashes on what line? What are the top frames on the stack of the crashed thread?
Quote:so I decided to check the retain count for each (CFURLRef)So I'm assuming the crash, or the line it occurred on said something about a CFURLRef?
Quote:and the retain count from the 1st view to the 2nd view is (2), but when when I go to the 3rd view the retain count drops to (0)I don't understand what this means at all. The retain count "from the 1st view to the 2nd view"? What does that mean? Do you mean you're swapping views and however you're doing the swap is affecting the retain count? Well how are you swapping them? Why didn't you post that code? Is the code above in just one of those views or exactly the same in all four? Or is this the code in a common view controller and your four views are sharing it and that's why the retain count is some dependent on the views?
MacSteve85 Wrote:What do you mean by (IIRC, the garbage collector)
IIRC means If I Remember Correctly.
The Objective-C 2.0 garbage collector might collect CFURLRefs, but I'm not familiar with whether it will collect CF objects. I thought it would, because they're usually toll-free bridged with their NS* counterparts.
I could be wrong though.
That you're even bothering with the retain-release paradigm indicates that you're not using the garbage collector though.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Releasing System sounds | MacSteve85 | 3 | 2,245 |
Jan 30, 2010 06:15 PM Last Post: MacSteve85 |
|

