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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:46:01+00:00 2026-05-26T06:46:01+00:00

I’m going to try and explain this without showing any code because I don’t

  • 0

I’m going to try and explain this without showing any code because I don’t think I need to…

I have an object i’ve created that contains data and several methods for accessing data from a web-server, in which case it then populates said data for later retrieval.

In the main thread, when the view initializes, I initialize this object with the URL it needs to access the data. This is all it does when it’s initialized… Then, once the view loads, I call one of the object’s methods which then grabs the data from the web-server. This can take several seconds or longer deepening on what data is being retrieved. After that, I can call other methods to get the different kinds of data that I need.

My problem is i can’t seem to find the best way to go about putting this into another thread. Doing a simple performSelectorInBackground doesn’t seem to work because the object I initialized when the view initialized can’t be accessed. The second thread can’t see it for what ever reason. I can, in theory, initialize the object and run the methods I need to run inside the second thread. Then pass the object back to the main thread… I’m looking at possibly doing a performSelectorOnMainThread and passing the object back that way. Would that work?

Ideally, it would be nice to have something that will let me:

  1. Run some code in another thread…
  2. Wait for said code to finish…
  3. Continue on with the rest of the program.

Its doesn’t seem like it’s that easy unfortunately. Any help that points me in the right direction here would be greatly appreciated. Or at least confirm that my theory about passing the object back would suffice.

EDIT: How can I read from and modify an instance variable i’ve defined in my header file for my view controller? When I put a break point in the method that is run in the second thread, it’s like the variable hasn’t been initialized.

EDITx2:

- (id)initWithText:(NSString *)strURL{
    if (self) {
        // Custom initialization
        osSearch = [[orgSearch alloc] initWithurl:strURL];
    }
    return self;
}
- (void)viewDidLoad{
    [self loadSearches];
    [super viewDidLoad];  
}
- (void)loadSearches{      
    [self performSelectorInBackground:@selector(workerThread) withObject:nil];
}
-(void) workerThread{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [osSearch go];
    [self performSelectorOnMainThread:@selector(returnToMain) withObject:nil waitUntilDone:FALSE];
    [pool release]; 
}
-(void)returnToMain{
        UITableView* tblView = tableView;
        tblView.frame = CGRectMake(0,28,320,387);
        [tblView release];
}

osSearch is the object i’m trying to access but it seems like all my ivars are being dealloced. if I put a break on the the performSelectorInBackground, I can see that osSearch was initialized correctly. Once i enter workerThread, it’s like it never was. I can comment out the call to “go” and just return to the main thread and it will still look like it’s never been initialized.

Just as a test, I created a new project, using the same threading method and object, I was able to create the new thread and access the view’s ivars and the objects ivars just fine. I don’t understand whats happening here. My only guess is the garbage collecter doesn’t like me, but thats just a guess. Again, any help would be great.

  • 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-05-26T06:46:01+00:00Added an answer on May 26, 2026 at 6:46 am

    1) There is no garbage collection in iOS. The memory management behaviour will always be consistent, up to non-deterministic behaviour of your own code (e.g. race conditions).

    If the same code works in a new project, then either it’s not exactly the same code, or it works by chance (accessing a deallocated object can work occasionally, it’s just a crash waiting to happen though) , or you have some non-deterministic conditions in your code which release the object.

    2) To do this:

    Run some code in another thread…

    Wait for said code to finish…

    Continue on with the rest of the program.

    You can use one of the following:

    1. performSelector… methods family, just like you used them.

    2. dispatch_async functions family – Look it up and you will find many
      examples.

    3. Use NSInvocationOperation/NSBlockOperation with a completion block
      which transfers control back to the main thread.

    4. Specifically for HTTP requests, you can use ASIHTTPRequest (also uses NSOperation internally, but provides a lot of extra functionality and callbacks for the request’s progress).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.