I have a static instance variable that is being used throughout my application. It has properties. These properties are used through my application and seem to work pretty well. However, sometimes the properties are released prematurely. What is odd is that the object that is pulling these properties keeps some and releases others. What would be a good way to insure that the properties of my object are not released prematurely.
Edit: It turns out that the issue was not premature releasing at all. It was a conversion issue. Thanks all for help.
@interface Game : NSObject
@property (nonatomic, strong) PFObject *gameObject;
//@property (nonatomic, strong) Concept *concept; // Will need to add Concept Object to GameObject once it's wrapper is done
@property (nonatomic, strong) User *initialPlayer;
@property (nonatomic, strong) User *invitedPlayer;
@property (nonatomic, strong) User *lastPlayedPlayer;
@property (nonatomic, strong) NSDate *lastPlayedDate;
@property (nonatomic, strong) NSDate *timeOutDate;
@property (nonatomic, assign) int timerTicks;
@property (nonatomic, assign) int currentRoundNumber;
@property (nonatomic, strong) User *winnerPlayer;
@property (nonatomic, assign) int initialPlayerPoints;
@property (nonatomic, assign) int invitedPlayerPoints;
@property (nonatomic, assign) int currentPlayerPoints;
@property (nonatomic, assign) GameStatus status;
@property (nonatomic, assign) int initialPlayerTimeouts;
@property (nonatomic, assign) int invitedPlayerTimeouts;
@property (nonatomic, assign) BOOL isInitialPlayer;
@property (nonatomic, strong) NSMutableDictionary *rounds;
@property (nonatomic, strong, readonly) Round *currentRound;
+(void)getActiveUserGameObjects:(PFUser *)user target:(id)target selector:(SEL)selector;
+(void)getYourTurnGameObjects:(PFUser *)user target:(id)target selector:(SEL)selector;
+(void)getTheirTurnGameObjects:(PFUser *)user target:(id)target selector:(SEL)selector;
+(void)getGameObjects:(PFUser *)user yourTurn:(id)yourTurn target:(id)target selector:(SEL)selector;
+(Game*)currentGame;
+(void)setCurrentGame:(Game*)currentGame;
..
//.m @implementation
..
static Game *sharedInstance = nil;
..
+(Game*)currentGame
{
return sharedInstance;
}
+(void)setCurrentGame:(Game*)currentGame
{
sharedInstance = currentGame;
}
...
#pragma mark - Player Setters and Getters
-(void)setInvitedPlayer:(User *)invitedPlayer
{
if (nil != invitedPlayer.userObject)
{
[self.gameObject setObject:invitedPlayer.userObject forKey:GAME_INVITED_PLAYER];
}
}
-(User*)invitedPlayer
{
NSObject *value = [self.gameObject objectForKey:GAME_INVITED_PLAYER];
if ([value isKindOfClass:[PFUser class]])
{
return [User userFromPFUser:(PFUser*)value];
}
return nil;
}
Holding onto them by maintaining a strong reference. It is extremely unlikely that ARC is randomly releasing your data. Much more likely is that you are letting go of it when you don’t mean to.
The first place I’d look is at your use of
setCurrentGame:, making sure that you’re not accidentally working on differentGameobjects at the same time in different parts of the program. First, make sure tYour
+get...methods are awkwardly named (agetprefix means a very specific thing in ObjC, and it’s not what you’re doing here). Havings class methods that take targets and actions like this seems a likely place to have trouble. It makes me wonder what’s going on inside there.Your conversion between two kinds of
Userobjects is a little suspicious, and I’d make sure you’re not accidentally dropping User or PFUser objects when you don’t mean to.Generally speaking, though, this question is over-vague. Are you winding up with dangling strong pointers? Are your strong pointers seeming to become
nil? Is your game object itself becomingnil? How do you know when things are being “released?” Or do you mean that they’re deallocating? Have you put a breakpoint indeallocto see who had the last reference to the object?