Reference getting lost for a view / Retain count becoming 0 abruptly - xcode

Joined
Jan 25, 2013
Messages
1
Reaction score
0
Points
1
LiveScoreSettingsView * livescoreSettings;
// initialisation in .h file inside @interface and no property is defined for this variable.

// 1st method

- (void)1stmethod: (id) callingClass username: (NSString*)username
{

livescoreSettings=callingClass; // retain count increases to 1
isLivescoresSettingsView = YES;
//.... some code where the above livescoreSettings variables are not used ... //

}



// 2nd method


- (void)2ndmethod: (id) callingClass username: (NSString*)username matchid: (NSString *) matchid eventType: (NSString *) eventType add: (NSString *) add

{

livescoreSettings=callingClass;
isLivescoresSettingsView = YES;
addEventToList = YES;

//.... some code where the above livescoreSettings variables are not used ... //
}



// delegate method thats activated when the response comes

- (BOOL)xmppStream: (XMPPStream *)sender didReceiveIQ: (XMPPIQ *)iq
{

// the block where the data is sent to a particular view to reload table

else if(isLivescoresSettingsView== YES || addEventToList == YES)
{

isLivescoresSettingsView=NO;
addEventToList = NO;


//.... some code where the above livescoreSettings variables are not used ... //

if(success)
NSLog(@"No Errors with retain count = %d ", [livescoreSettings retainCount]);
else
NSLog(@"Error Error Error!!!");

[livescoreSettings.tableView reloadData];

// when 2ndmethod is called there's no memory reference to livescoreSettings, tableView delegate methods are not called which is obvious. But not sure why the retain count is reducing abruptly.

}

}


Whats happening is that 1st time i call that 1stmethod method everything works fine and the reference to the livescoreSettings is retained.

Next when i call 2ndmethod method also the livescoreSettings ref is retained but by the time the delegate method gets activated the reference of that variable is lost.. dont know why...
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Your code is not helping us much, I'm guessing your livescoreSettings is a view, or custom NSView object.

What delegate methods ?, NSView does not have a delegate protocol, but can have a delegate assigned.
where are the delegate methods located, eg. AppDelegate?

why are you creating livescoreSetting from (id)callingClass?
That would imply that the callingClass could be a different class type from NSView.

in short you will have to help us to help you.

If your instance variable is pointing to nil, then it has been released, or not initialized, in the case of
an NSView class, it can bee released automatically when the view is removed from the screen, when
you are using ARC memory managment.

Also check the scope of your instance variables, make sure that all of the methods that use it, are able
to see it.

Also put your code snippets in code tags for posting, it makes it easier to read, for example.

Code:
 myCode

Sorry I could not be more help, but you will have to be more specific where your code is breaking down.

Also put lots of NSLog(@""); statements in the critical program methods, so that you can track the
changes in your variables.

Regards Mark
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
It's just ocured to me that your problem may lie with the callingClass object, if at some point the callingClass object is released, then the livescroreSettings object will also be released or point to nil, as in the example code you have posted, livescroreSettings and callingClass are pointing at the same memory space, this is more likely if you are using ARC.

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top