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 06-23-2011, 06:46 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: Cardiff
Posts: 79
AyClass is on a distinguished road
Exclamation How can i fix this memory leak?

hi im creating a soundboard and everything works fine when running the app but i have many memory leaks can someone see whats wrong?

.m
Code:
-(IBAction)oldskool {
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"oldskool",CFSTR ("wav"),NULL);
    
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
    
}
AyClass is offline   Reply With Quote
Old 06-23-2011, 07:26 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

If you check the documentation for CFBundleCopyResourceURL, it's pretty easy to figure out.

See here: Loading…

It says

Quote:
Return Value
A CFURL object describing the location of the requested resource, or NULL if the resource cannot be found. Ownership follows the Create Rule.
And the Create Rule is: Loading…

So your answer is: CFRelease
baja_yu is offline   Reply With Quote
Old 06-23-2011, 07:38 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: Cardiff
Posts: 79
AyClass is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
If you check the documentation for CFBundleCopyResourceURL, it's pretty easy to figure out.

See here: Loading…

It says



And the Create Rule is: Loading…

So your answer is: CFRelease
Thankyou very much

in my case it would be
Code:
CFRelease(soundFileURLRef);
right?
AyClass is offline   Reply With Quote
Old 06-23-2011, 07:40 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Bingo!
baja_yu is offline   Reply With Quote
Old 06-23-2011, 07:43 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: Cardiff
Posts: 79
AyClass is on a distinguished road
Default

haha Thanks!

by the way is this an appropriate way of playing a sound when a button is pressed? i see many others doing it a different way

im using the audiotoolbox framwork
AyClass is offline   Reply With Quote
Old 06-23-2011, 07:49 PM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

There's a few ways to go about it. The choice of which depends on the file itself (format, length) and its purpose. There's a section of the Multimedia Programming guide devoted to it which explains which is used when: Loading…
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
memory leak, memory leaking, memory leaks, memory management, soundboard

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: 334
8 members and 326 guests
chemistry, Dnnake, iOS.Lover, lendo, leostc, Leslie80, pbart, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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