So, i created an object that will just hold 6 variables.
#import <Foundation/Foundation.h>
@interface UserInfoData : NSObject
{
NSNumber *dealerID;
NSNumber *growerID;
NSNumber *UID;
NSNumber *uLevel;
NSString *fName;
NSString *lName;
NSString *state;
}
@property (nonatomic, retain) NSNumber *dealerID;
@property (nonatomic, retain) NSNumber *growerID;
@property (nonatomic, retain) NSNumber *UID;
@property (nonatomic, retain) NSNumber *uLevel;
@property (nonatomic, retain) NSString *fName;
@property (nonatomic, retain) NSString *lName;
@property (nonatomic, retain) NSString *state;
@end
#import "UserInfoData.h"
@implementation UserInfoData
@synthesize dealerID;
@synthesize growerID;
@synthesize UID;
@synthesize uLevel;
@synthesize fName;
@synthesize lName;
@synthesize state;
-(void) dealloc
{
[dealerID release];
[growerID release];
[UID release];
[uLevel release];
[fName release];
[lName release];
[state release];
[super dealloc];
}
@end
View Controller A
.h file:
@class UserInfoData;
.m file:
#import "UserInfoData.h"
iPhoneAppDelegate *dataCenter = (iPhoneAppDelegate *) [[UIApplication sharedApplication] delegate];
UserInfoData *userInfoData = [[[UserInfoData alloc] init];
userInfoData.dealerID = [NSNumber numberWithInt:[[userInfo objectForKey:@"dealerid"] intValue]];
userInfoData.growerID = [NSNumber numberWithInt:[[userInfo objectForKey:@"growerid"] intValue]];
userInfoData.UID = [NSNumber numberWithInt:[[userInfo objectForKey:@"uid"] intValue]];;
userInfoData.uLevel = [NSNumber numberWithInt:[[userInfo objectForKey:@"ulevel"] intValue]];;
userInfoData.fName = [userInfo objectForKey:@"f_name"];
userInfoData.lName = [userInfo objectForKey:@"l_name"];
userInfoData.state = [userInfo objectForKey:@"state_prov"];
NSArray *userInfoArray = [NSArray arrayWithObjects:userInfoData, nil];
dataCenter.userInfoList = userInfoArray;
[userInfoData release];
i save the data to my AppDelegate which i use as a data center. i need this data in another view controller. i also repeat this process of initializing and releasing in 2 other functions.
View Controller B
.h file:
@class UserInfoData;
.m file:
#import "UserInfoData.h"
UserInfoData *userInfoData = [[[UserInfoData alloc] init] autorelease];
userInfoData = [dataCenter.userInfoList objectAtIndex:0];
//do stuff here
[userInfoData release];
by manually releasing the objects, this would cause issues when i tried to retrieve it from my datacenter in view controller B, i would get the wrong memory location and get the wrong data (which crashed the program).
when i switched and used only autorelease when initializing the object, it works fine. what am i missing about memory management? i do not have leaks, but i do have a bunch of "Incorrect decrement of the reference count of an object that is not owned at this point by the caller" which i can not track down (xcode does not tell me which object, the line its on, or give me a blue indicator on the line number in the code pane like it does for warnings and errors). could those be causing memory pointing to the wrong memory locations? but if that is happening, why would autoreleasing them fix it?