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 09-18-2010, 03:36 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 2
thecfguy is on a distinguished road
Default NSString stringwithformat create memory leak in loop

Hi Guys,
I am having issue of memory leak for NSString stringWIthForm

Below is code written in function which call on Onviewdidload event. Function load photo asynchronously from server, first time load I didn't get any issue but as I move to another view (using navigationcontroller) and come back to same view showing multiple memory leak (size of photos array).

I have tried with [NSString alloca] initWithString and release at end of loop but still not work.

Can anyone help me to find out where I am going wrong and where it is leaking exactly?

Any help will be appreciated..

PHP Code:
for (NSArray *photo in photos) {
        
NSAutoreleasePool pool = [[NSAutoreleasePool allocinit];
        
NSString *strURL = [photo objectAtIndex:[self indexByColumnName:@"FILENAME"]];
        
NSString *strThumbURL,*strFormattedURL;
                
        if ([
strURL hasPrefix:@"http"]) {
            
//Cloude hosted photos
            
strThumbURL=[NSString stringWithFormat:@"%@/th_%@",[strURL stringByDeletingLastPathComponent],[strURL lastPathComponent]];
            
strFormattedURL = [NSString stringWithFormat:@"%@",strURL];
        }
        else{
            
strThumbURL=[NSString stringWithFormat:@"%@%@/th_%@",WEBSERVICE_URL,[strURL stringByDeletingLastPathComponent],[strURL lastPathComponent]];
            
strFormattedURL = [NSString stringWithFormat:@"%@%@",WEBSERVICE_URL,strURL];
        }
        
        
NSURL *url = [NSURL URLWithString:strThumbURL];

        
thumbView = [[ThumbImageView allocinitWithURL:url];
        
        [
thumbView setDelegate:self];
        
        
CGRect frame = [thumbView frame];
        
frame.origin.THUMB_V_PADDING;
        
frame.origin.xPosition;
        [
thumbView setFrame:frame];
        [
thumbView setImageURL:strFormattedURL];
        [
thumbScrollView addSubview:thumbView];
        [
thumbView release];
        
        
xPosition += (frame.size.width THUMB_H_PADDING);
        if (
i==0) {
            [
self pickImageWithURL:[thumbScrollView.subviews objectAtIndex:0]];
            
i++;
        }
        [
pool release];
    } 
thecfguy is offline   Reply With Quote
Old 09-18-2010, 06:13 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

There is no reason to create any new auto release pools for each photo. Stop doing that.
RLScott is offline   Reply With Quote
Old 09-18-2010, 01:35 PM   #3 (permalink)
N3RD
 
Join Date: Oct 2009
Posts: 201
tychop is on a distinguished road
Default

Does the problem still occur is you don't use autorelease strings and get rid of your autorelease pool?
Code:
NSString *test = [[NSString alloc] initWithString:@"stringContents"];
// use string
[test release];

// or

NSString *test = [NSString alloc];
[test initWithString:@"stringContents"];
// use string
[test release];
tychop is offline   Reply With Quote
Old 09-19-2010, 01:31 PM   #4 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Shouldn't you call
[myautoreleaspool drain];
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Reply

Bookmarks

Tags
memory leaks, nsstring

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: 304
15 members and 289 guests
2ndSegment, cayladv57, cgokey, dermotos, djohnson, Domele, Hamad, heshiming, linkmx, markuschow, pungs, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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