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 6630545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:25:09+00:00 2026-05-25T22:25:09+00:00

I did a build and analyze and was warned about a potential leak of

  • 0

I did a build and analyze and was warned about a potential leak of an object stored into ‘locationManager’. I was wondering how this should be handled properly. Here’s the code:

// Compass Code

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    if ([CLLocationManager locationServicesEnabled] && 
        [CLLocationManager headingAvailable]) {
        [locationManager startUpdatingLocation];
        [locationManager startUpdatingHeading];
        locationManager.headingFilter = 2; // 2 degrees

    } else {

    NSLog(@"Can't report heading");

    }

thanks for any help

  • 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-25T22:25:10+00:00Added an answer on May 25, 2026 at 10:25 pm

    On the first line you alloc the location manager. This means you own that reference, and you should release it when you are done.

    You need to either release the location manager when you have finished setting it up:

    // ...
    locationManager.headingFilter = 2; // 2 degrees
    [locationManager release];
    

    Or autorelease it on the same line you alloc it:

    CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
    

    Having said that, you should probably be storing the location manager in an instance variable so you can stop the location updates at some point. Otherwise self might get deallocated and the location manager will continue sending messages to that deallocated object. This will cause a crash.

    After making an instance variable, your dealloc should probably have this:

    - (void)dealloc
    {
        // ...
        locationManager.delegate = nil;
        [locationManager stopUpdatingLocation];
        [locationManager release];
        // ...
        [super dealloc];
    }
    

    Clearing the delegate will make sure the location manager will not send any messages to us once we have been deallocated. Then we stop the location updates and release the instance variable because we no longer need it.

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

Sidebar

Related Questions

I did the Build and analyze in xCode and get Dereference of null pointer
I recently integrated Cobertura into my Ant build scripts and I am wondering if
Note: I inherited this site, I did not build it. The home page is
Is it possible to bulk update? I did a build insert, now I would
On my first job interview, I was asked why did I build my own
I've just mad Build and Analyze with my project on iphone, and i got
I did build ffmpeg for Android in winxp and scientific linux , ffmpeg is
We have a web application and I did the build and deploy scripts to
My project had no errors until I did a build. Here's the error log.
I have jenkins set up to build any branch and merge it into master.

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.