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 8735029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:57:42+00:00 2026-06-13T09:57:42+00:00

I wouldn’t normally ask questions like this, but I really cant get my head

  • 0

I wouldn’t normally ask questions like this, but I really cant get my head around it. I have a class ‘GetTableInfoFromDatabase’, which connects to my database and downloads some JSON. This works great from the first screen of my tab-bar application. I can call the getNewData method as much as I want to effectively refresh the data.

My problem arises when I try and create an instance of the ‘GetTableInfoFromDatabase’ class and call the very same method from another tab. I get the following error:

*** -[GetTableInfoFromDatabase respondsToSelector:]: message sent to deallocated instance 0x1d89e830

The funny thing is, i’m using ARC. The culprit (in my opinion) is ASIHTTPRequest. I have had to enable -fno-objc-arc to get the project to compile. This library is used in the GetTableInfoFromDatabase class.

Here is the class:

- (void) getEventDataWithSender:(id)sender{


ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"-------.com/getdata.php"]];
[request setDelegate:self];
NSLog(@"Running!");
[request startAsynchronous];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
}

And this is how i’m calling it:

GetTableInfoFromDatabase *getInfo = [[GetTableInfoFromDatabase alloc]init];
[getInfo getEventDataWithSender:self];

I’ve even changed the order of the tabs around, so the first tab to be displayed purely just calls this method, nothing else. Not even before the ‘GetTableInfoFromDatabase’ has been previously initialised by the class that initialised it first last time. Still crashes.

Has anyone got any ideas? This is so frustrating!

  • 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-13T09:57:43+00:00Added an answer on June 13, 2026 at 9:57 am

    You need to assign that variable to a property if you plan on exposing it to other view controllers. ARC will, and should, immediately deallocate getInfo after this code executes:

    GetTableInfoFromDatabase *getInfo = [[GetTableInfoFromDatabase alloc]init];
    [getInfo getEventDataWithSender:self];
    

    So if this line is included in say viewDidLoad: and nothing else refers to getInfo in that method, it will be immediately released. Why, because you haven’t told the compiler that it should retain it.

    So in the view controller that’s exposing this class, on whatever tab it might be a child of… you would do something like this:

    ViewController.h

    @class GetTableInfoFromDatabase;  // forward declaration
    
    @interface ViewController : UIViewController
    
    @property (strong, nonatomic) GetTableInfoFromDatabase *getInfo;
    

    ViewController.m

    @implementation ViewController
    
    @synthesize getInfo = _getInfo;
    
    - (void) viewDidLoad {
        [super viewDidLoad];
    
        self.getInfo = [[GetTableInfoFromDatabase alloc]init]; // assign your value to a property
    
        [self.getInfo getEventDataWithSender:self];
    }
    

    So when you declare your property as Strong in your header, it will maintain a strong reference to it. @Synthesize getInfo = _getInfo means that it will create a getter and setter for self.getInfo around an instance variable named _getInfo. If you didn’t want to expose it as a property, just an instance variable… you could do this:

    ViewController.h

    @class GetTableInfoFromDatabase;  // forward declaration
    
    @interface ViewController : UIViewController {
        GetTableInfoFromDatabase _getInfo;
    }
    

    ViewController.m

    @implementation ViewController
    
    - (void) viewDidLoad {
        [super viewDidLoad];
    
        _getInfo = [[GetTableInfoFromDatabase alloc]init]; // assign your value to a property
    
        [_getInfo getEventDataWithSender:self];
    }
    

    By default, the compiler will maintain a strong reference to that instance variable unless otherwise specified. You can have weak references as well, and all of those options are pretty well documented. So with ARC, or plain old memory management in general, you need to make an instance variable or property if you want it to hang around for a while.

    Honestly… all ARC is doing for you is keeping you from having to call retain and release. Before ARC, setting that property would look like this:

        GetTableInfoFromDatabase getInfo = [[GetTableInfoFromDatabase alloc]init];
    
        self.getInfo = getInfo;
    
        [getInfo release];
    

    Now with ARC, the compiler just writes that code for you 😉 Hope this helps!

        [self.getInfo getEventDataWithSender:self];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally i wouldn't put a title like this in the question, but i'm pretty
I wouldn't normally ask this kind of question on here, but unfortunately whilst AutoMapper
I normally wouldn't do this, but the project I'm currently working on requires a
So I wouldn't be stupid enough to ask this in general, but here's the
I thought I wouldn't need to ask this but I am not having any
Why wouldn't MySQL have this feature? INSERT INTO abc (a) VALUES ('bla') ON DUPLICATE
I wouldn't mind writing my own function to do this but I was wondering
I wouldn't ask if i wasn't sure that i have 100% no idea why
Why wouldn't C++ allow something like that ? I need to have multiple priority
I wouldn't ask if I couldn't find it anywhere else, but I've run into

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.