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

  • Home
  • SEARCH
  • 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 7539451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:23:07+00:00 2026-05-30T07:23:07+00:00

I am new to iPhone objectiveC development. I am getting memory leaks when I

  • 0

I am new to iPhone objectiveC development. I am getting memory leaks when I run the following method.

- (NSString *) getDBPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    return [documentsDir stringByAppendingPathComponent:@"dbname.sqlite"];
}

and I have found that if I trim it down to just the following… it still leaks

 - (NSString *) getDBPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    return nil;
}

so i tried releasing the paths variable with the following, which still leaks memory.

 - (NSString *) getDBPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    [paths release];
    return nil;
}

To detect the leak, I am running it in the profiler with the following loop:

for (int iLoop = 0; iLoop < 30; iLoop++) {
    NSString *dbPath = [self getDBPath];
    [dbPath release];
    sleep(1);
}

The amount of memory associated with NSPathStore2 and NSArrayM continues to grow.

Any suggestions on what I a might be doing wrong?
thanks!

  • 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-30T07:23:08+00:00Added an answer on May 30, 2026 at 7:23 am

    Your code for getDBPath is fine, but it is probably called from a context without any autorelease pool.

    Fix it by allocating your own pool in the loop code:

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    for (int iLoop = 0; iLoop < 30; iLoop++) {
        NSString *dbPath = [self getDBPath];
        // [dbPath release]; // do not release! dbPath will be autoreleased
        sleep(1);
    }
    [pool drain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to iPhone development and I'm still getting my head around Objective-C,
I am new in iphone development.I am using -(NSString *)Base64Encode:(NSData *)data { //Point to
I'm new to Objective-C and iPhone SDK development. I want to call a method
I'm new to iPhone development, and am sort-of getting there with pointers in Objective-C.
I'm new to Objective-C and iPhone development, and I'm trying to store floating-point values
I am new to Objective C and iPhone development. I am using CoreData on
I am fairly new to a objective-c or in whole mac/iphone development. My question
When building a new iPhone app in Xcode, I'm getting this error: codesign error:
I'm new to iPhone/Objective-C development. I jumped the gun and started reading and implementing
I'm new to iPhone development, so apologies if this is a silly question, 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.