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

  • Home
  • SEARCH
  • 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 9226679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:53:18+00:00 2026-06-18T04:53:18+00:00

I have a View object becoming nil abruptly in my method. I am not

  • 0

I have a View object becoming nil abruptly in my method.

I am not using ARC

no threading is involved


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…

@interface XY {
    LiveScoreSettingsView * livescoreSettings; // initialisation in .h file inside    
}
@end

@implementation

// 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.
    }
}

@end
  • 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-06-18T04:53:19+00:00Added an answer on June 18, 2026 at 4:53 am

    The issue is that you are not taking ownership of livescoreSetting that is being passed into 1stmethod or 2ndmethod. If you are not using ARC then you will need to retain it in those methods and release it in your dealloc method (simply assigning the instance to livescoreSetting does not increase the retain count when using MRR).

    Imagine if 1stmethod is called in this way:

    LivescoreSettingsView *view = [[LivescoreSettingsView alloc] init];
    [whateverItsCalled 1stmethod:view;         // (1)
    [view release];                            // (2)
    

    Then view is being assigned to whateverItsCalled.livescoreSetting at (1), but the retain count is 1. After (2) the retain count is 0, however whateverItsCalled.livescoreSetting is now a dangling pointer and I’m surprised you don’t see messages like “message sent to deallocated object” rather than the errors you are seeing (I cannot see why it’s being assigned to nil when ARC is not involved).

    To solve the problem, you need to synthesize your setter/getter methods for the instance variable by adding a @property for it. I prefer to name the instance variables using a leading underscore (_) to differentiate them from the setter/getter methods names; so:

    .h file:

    @interface WhateverItsCalled : NSObject
    {
        LiveScoreSettingsView *_livescoreSetting;
    }
    
    @property (retain, nonatomic, readwrite) LiveScoreSettingsView *livescoreSetting;
    

    .m file:

    @implementation WhateverItsCalled
    @synthesize livescoreSetting = _livescoreSetting;
    
    - (void)dealloc
    {
        self.livescoreSetting = nil;           // Release the object by assigning nil
        [super dealloc];
    }
    
    - (void)firstmethod:(id) callingClass username:(NSString*)username
    {
        self.livescoreSettings = callingClass;   // Note the use of self!
        isLivescoresSettingsView = YES;
    }
    
    - (void)secondmethod:(id)callingClass username:(NSString*)username matchid:(NSString *) matchid  eventType:(NSString *) eventType  add:(NSString *) add
    
    {
        self.livescoreSettings = callingClass;   // Note the use of self!
        isLivescoresSettingsView = YES;
        addEventToList = YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a an object view with data and a button on that view.
I have a View (created using Backbone.View.extend) and a JSON object, I actually get
In the following code I have a view object that is an instance of
I have a View Model object that has a depednency property called IsSearching ;
I have a view that displays object information when the correct URL is provided
I have a custom Grid view object that inherits from the base System.Web.UI.WebControls.GridView. The
In my application, we have a view model object from which we're retrieving its
I have this class: class View(object): def main_page(self, extra_placeholders = None): file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'
I have a parent-child view model object structure set up and need to update
I have the following requirement. I submit a Model object to a view as

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.