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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:31:33+00:00 2026-05-13T18:31:33+00:00

I am using Apple’s MyGizmoClass Singleton class for program-wide session variables and loving it!

  • 0

I am using Apple’s MyGizmoClass Singleton class for program-wide “session variables” and loving it! However, when I run “Build and Analyze” it gives weird results. Maybe my usage is wrong (it works, but it may be working due to a flakey side effect). Here is an example.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    int ct = 0;
    MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];
    ct = [[myGizmoClass searchResultsForResortLocation] count];
    [myGizmoClass release];
    NSLog(@"ct: %d",ct);
    return ct;
}

or

- (void)viewWillAppear:(BOOL)animated {


     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
     //self.navigationItem.rightBarButtonItem = self.editButtonItem;

    NSMutableString *which_resort = [[NSMutableString alloc] init];
    NSMutableString *category_code = [[NSMutableString alloc] init];
    MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];

    ...

    which_resort = [self which_resort_location_are_we_in];

    ... 
    [myGizmoClass setWhich_resort:which_resort];

    int useDebugMode = [myGizmoClass useDebugMode]; 

    ...


    [myGizmoClass release];

    [which_resort release];
    [category_code release];

    [super viewWillAppear:animated];

}

Again, this usage may be WAY off, but I thought each method I used a value from the singleton I had to do:

MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];

and

[myGizmoClass release];

BUT i am getting these errors during Analyze:

/Users/jgobble/Documents/ProgramName/Classes/ResortsListViewController.m:495:2
Incorrect decrement of the reference
count of an object is not owned at
this point by the caller
/Users/jgobble/Documents/ProgramName/Classes/ResortsListViewController.m:493:30
Method returns an Objective-C object
with a +0 retain count (non-owning
reference)
/Users/jgobble/Documents/ProgramName/Classes/ResortsListViewController.m:495:2
Incorrect decrement of the reference
count of an object is not owned at
this point by the caller

Now, please take this into account: I am calling this:

MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];

at the beginning of EVERY method need a “session variable” and then calling:

[myGizmoClass release];

at the end of that method PRIOR to returning a result (if i return a result from that function.

Is this not the way I should do it?

This is the ONLY thing that the analyzer (thank goodness) is reporting wrong with the program. I do not know if i should ignore it. I do not know if I am doing the calls in the right place.

Here is another question I am worried about: Does this work or do the subsequent calls to *myGizmoClass mess anything up?

-(void) function_a {
     MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];

     [myGizmoClass setC:1];

     int result_b = [self function_b];

     printf("Addition result is: %d", result_b);

     [myGizmoClass release]
}

-(int) function_b {
     MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager];

     int b = 0;

     b = b + [myGizmoClass c];

     [myGizmoClass release]

     return b;
}

(i have not tested the code above)

In other words there anything wrong with calling MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager]; from function_b when you have not released MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager]; from function_a?

  • 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-13T18:31:33+00:00Added an answer on May 13, 2026 at 6:31 pm

    The problem is the way that you are using a singleton. The general idea is that you don’t retain or release any singleton objects, because there is only one instance that hangs around, and the Apple implementation of singletons are coded in such a way that you can’t. This brings about some issues that Peter Hosey blogged about with a better implementation of a Cocoa singleton.

    The warnings that the Analyzer logs are simply stating that you “shouldn’t” retain or release the singleton object; by virtue of the fact that you call [MyGizmoClass sharedManager] you shouldn’t be releasing anyway (following the Cocoa memory management guidelines).

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

Sidebar

Ask A Question

Stats

  • Questions 409k
  • Answers 409k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming you are using Flex Builder, you could try the… May 15, 2026 at 7:08 am
  • Editorial Team
    Editorial Team added an answer If you are learning the C++ language itself, you probably… May 15, 2026 at 7:08 am
  • Editorial Team
    Editorial Team added an answer I can understand how you arrived at your current solution.… May 15, 2026 at 7:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.