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 07-26-2009, 03:48 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 7
iphoneguy777 is an unknown quantity at this point
Unhappy Memory Leak in Flipsideviewcontroller.m, Please help

Hello:

I'm trying to get rid of a leak in my flipsideviewcontroller.m file and I'm not sure where I'm going wrong. I have two releases for my retains but when I run "leaks" in instruments in points me to this file and that UIImages are leaking. Any help analyzing this info would be greatly appreciated.

// random from 11 images "girl0_9"
NSString *fileName = [NSString stringWithFormat:@"girl%d_%d", gCategory, rand];

// NSLog(@"load image %@", fileName);

// UIImage *img = [[UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"]] retain];
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"]];
// [fileName release];
// UIImage *img = [[UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"menu_bg" ofType:@"png"]] retain];

[bgImage setImage:img];
//[img release];

Thanks,
Iphoneguy777
iphoneguy777 is offline   Reply With Quote
Old 07-26-2009, 04:11 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Just a tip: it's probably best to remove commented lines from your sample code before posting to avoid confusion.

I don't see anything that would be a leak, per se. You are creating autoreleased objects, so those may be sticking around for a bit. Is Leaks saying that you have a leak, or are you merely investigating and observing that the images still exist longer than you expect?

When in doubt, avoid autoreleased objects. Ex:

Code:
NSString *fileName = [[NSString alloc] initWithFormat:@"girl%d_%d", gCategory, rand];

UIImage *img = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"]];

[bgImage setImage:img];

[img release], img = nil;
[fileName release], filename = nil;

I don't think that Leaks will report autoreleased items as "leaks", so if you are getting the little leak spike in your graph, then the issue is probably somewhere else.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-26-2009, 05:12 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 7
iphoneguy777 is an unknown quantity at this point
Default Your answer fixed the leak! Bought your app! Thanks.

You made my day. Got your app, I'm excited to try it out. Thanks a lot.

Quote:
Originally Posted by BrianSlick View Post
Just a tip: it's probably best to remove commented lines from your sample code before posting to avoid confusion.

I don't see anything that would be a leak, per se. You are creating autoreleased objects, so those may be sticking around for a bit. Is Leaks saying that you have a leak, or are you merely investigating and observing that the images still exist longer than you expect?

When in doubt, avoid autoreleased objects. Ex:

Code:
NSString *fileName = [[NSString alloc] initWithFormat:@"girl%d_%d", gCategory, rand];

UIImage *img = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"]];

[bgImage setImage:img];

[img release], img = nil;
[fileName release], filename = nil;

I don't think that Leaks will report autoreleased items as "leaks", so if you are getting the little leak spike in your graph, then the issue is probably somewhere else.
iphoneguy777 is offline   Reply With Quote
Reply

Bookmarks

Tags
memory leak

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: 321
11 members and 310 guests
chiataytuday, coolman, givensur, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,882
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:20 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0