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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:21:39+00:00 2026-06-14T19:21:39+00:00

i have a non arc project. i’m trying to use dispatch_async to get data

  • 0

i have a non arc project. i’m trying to use dispatch_async to get data from server and save it in sqlite. the dispatch_async happens inside a method with callback. on calling the method the app crashes with exc bad access. here is how i’ve implemented the code.

- (void) HandleData:(const char*) receivedData WithSuccess:(void(^)(BOOL finishing))completed
{
dispatch_queue_t fetchQ = dispatch_queue_create("Refreshing", NULL);
dispatch_async(fetchQ, ^{

   [self write_data_in_sqlite]//    **<--crash happens here in the method which is called here**
    }
    dispatch_sync(dispatch_get_main_queue(), ^{
            completed(YES);
    });
});
dispatch_release(fetchQ);
}

and i call the method as follow:

HandleResponse *handleResponse = [[[HandleResponse alloc] init] autorelease];
                [handleResponse HandleData:aData WithSuccess:^(BOOL finishing) {
                 if(finishing)
                 {
                 //update the UI here
                 }
                 }];

if i remove the dispatch_async then it doesnt crash, but my UI gets blocked while writing to the sqlite.

what am i doing wrong?

edit:
removing the block and using dipatch_async produces the same exc_bad_access crash.

edit 2:
i tried example answer given below, it still crashes.

i thought to copy it then autorelease it. it crashes still but nit that often. i’m gonna check for memory leak. i’ll report.

HandleResponse *handleResponse = [[[HandleResponse alloc] init] autorelease];
        [handleResponse HandleData:aData WithSuccess: [[^(BOOL finishing) {
         if(finishing)
         {
         //update the UI here
         }
         } copy] autorelease];

edit 3:

the crash happens in strlen even the xml content is in xmlResopnse. but why this happen with dispatch and not without it

xmlDocPtr xml= xmlParseMemory(xmlResopnse, strlen(xmlResponse);

edit 4:
as in answer below suggested not to use c objects in dispatch async. so i converted xmlResponse from const char* to nsstring and it doesnt crash.

  • 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-14T19:21:40+00:00Added an answer on June 14, 2026 at 7:21 pm

    Everything you’ve shown seems to be okay in terms of blocks and memory management. It must be something else.

    I notice that you’re passing in a C string (the char pointer receivedData) that you’re not using. If you’re not showing us the real code, and you are actually using the receivedData variable in the block, then that could be a problem, because the block simply captures the char pointer, but does not manage the memory of the string behind the pointer (it is not an Objective-C object). Therefore, it is possible that the C string is only valid in the calling scope (before the asynchronous operation), and no longer valid when the asynchronous operation runs. Your statement that something is crashing at strlen supports the idea that there is something wrong with some C string. You should try using NSString objects instead, since as objects they are properly memory-managed by blocks.

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

Sidebar

Related Questions

I'm trying to move an existing non-ARC project to ARC. I have set the
I have never worked on non ARC based project. I just came across a
I have an ARC project and I'm trying to add AFNetworking to it. In
I have a ARC enabled Mac project with a non-ARC enabled framework, all compiles
I have an non ARC project. So i am maintaining its memory management. It
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
I wrote a macro from scratch but would like to have non-technical people install/run
I have found how to implement singleton in objective c (Non-ARC). Matt Galloway's singleton
Auto generating entities from a legacy database. Many of the tables have non standard
I am working on a ARC based project . I have never worked on

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.