Hi all!
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?