Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:06:31+00:00 2026-05-25T00:06:31+00:00

I’m kinda new in finding memory leaks in objective c and how to fix

  • 0

I’m kinda new in finding memory leaks in objective c and how to fix them. I’m know how to use alloc/init/copy and release/retain but ( a least i think so 🙂 ) but i have some strange memory leaks in my IOS app.

-(void) sendStats {

// read the app settings
plistHandler *readData  = [[plistHandler alloc] init];
[readData setPlistName:@"Settings"];
NSDictionary *settingsArray  = [readData readPlist];
[readData release];

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumber = [f numberFromString:[NSString stringWithFormat:@"%@", [settingsArray objectForKey:@"range"]]];
[f release];

int rangeForUrl;

if(myNumber != nil) {
    rangeForUrl = [myNumber intValue];
} else {
    rangeForUrl = 10;
}

// get uniqe device ID
UIDevice *getdev = [UIDevice currentDevice];
NSString *uniqueIdentifier = [getdev uniqueIdentifier];

NSString *deviceId  = [NSString stringWithFormat:@"IOS-%@", uniqueIdentifier];

// get the unix timestamp
NSDate * past = [NSDate date];
NSTimeInterval oldTime = [past timeIntervalSince1970]; 
NSString * unixTime = [[[NSString alloc] initWithFormat:@"%0.0f", oldTime] autorelease];


// send the data with a post request to the API
HttpRequest *data = [[HttpRequest alloc] init];
data.postData   = [NSString stringWithFormat:@"&device=%@&age=%@&gender=%@&latitude=%@&longitude=%@&timestamp=%@", deviceId, [settingsArray objectForKey:@"age"], [settingsArray objectForKey:@"gender"], @"00", @"00", unixTime];

data.controller = @"sendDevice";

NSString *url   = [NSString stringWithFormat:@"http://www..eu/api/send_device"];

[data loadHostName:url];

[data release];

//NSLog(@"string s: %@", data.postData);

}

This is the memory leak according to Xcode instruments => leaks:

Leaked Object # Address Size Responsible Library Responsible Frame
NSCFString, 0x16cb40 144 Bytes Foundation -[NSPlaceholderString initWithFormat:locale:arguments:]

This is the line with “data.postData = …” in my code. Can someone help me out?

this is how I use postData in the class httpRequest:

- (void)loadHostName:(NSString *)hostName {



responseData = [[NSMutableData alloc] init];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", hostName]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

if(authString) {
    [request setValue:authString forHTTPHeaderField:@"Authorization"];
}

if([postData isKindOfClass:[NSString class]] && postData != @"") {

    NSData *dataToPost = [postData dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d",[dataToPost length]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:dataToPost];

}

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];

}

with of course:

NSString *postData;
@property (nonatomic, retain) NSString *postData;

and

@synthesize postData;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:06:31+00:00Added an answer on May 25, 2026 at 12:06 am

    You need to release postData in dealloc.

    looks like its fixed now. But i dont really understand how the dealloc works. I never did a
    alloc/init on postData. Does this mean every object in my .h file like
    postData need to be released in the dealloc in the .m file?

    Speaking of properties, you need to release in dealloc all your properties not marked assign (along with any non-property instance variable you own). Non-assign properties own the object held by the backing instance variable so you need to relinquish ownership of it by sending it a release message in dealloc.

    From “The Objective-C Programming Language”:

    Declared properties, along with the @synthesize directive, take the
    place of accessor method declarations; when you synthesize a property,
    the compiler creates accessor methods as needed. However, there is no
    direct interaction between property declaration and the dealloc
    method—properties are not automatically released for you. Declared
    properties do, however, provide a useful way to cross-check the
    implementation of your dealloc method: you can look for all the
    property declarations in your header file and make sure that object
    properties not marked assign are released, and those marked assign are
    not released.

    I would also recommend you to read the “Memory Management Programming Guide”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.