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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:01:18+00:00 2026-06-17T17:01:18+00:00

I am getting a spin lock error whenever I send my application to the

  • 0

I am getting a spin lock error whenever I send my application to the background. Here is the code I have when the application is minimized:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    if (savedResults || savedSchedule || watchingClasses || professors) {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *docDir = [paths objectAtIndex:0];
        NSString *fullPath = [docDir stringByAppendingFormat:@"/%@", kFileName];
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:4];
        if (!savedResults)  {
            [array addObject:[NSNull null]];
        }else {
            [array addObject:savedResults];
        }
        if (!savedSchedule) {
            [array addObject:[NSNull null]];
        }else {
            [array addObject:savedSchedule];
        }
        if (!watchingClasses) {
            [array addObject:[NSNull null]];
        }else {
            [array addObject:watchingClasses];
        }
        if (!serverAnnouncements) {
            [array addObject:[NSNull null]];
        }else {
            [array addObject:serverAnnouncements];

        }if (!professors) {
            [array addObject:[NSNull null]];
        }else {
            [array addObject:professors];
        }
        [NSKeyedArchiver archiveRootObject:[array copy] toFile:fullPath];
    }
        //close connection
    if (outputStream) {
        if ([outputStream hasSpaceAvailable]) {
            dispatch_queue_t task = dispatch_queue_create("Close Connection", nil);
            NSString *str = @"_CLOSE_CONNECTION*\n";
            NSData *dataToSend = [[NSData alloc] initWithData:[str dataUsingEncoding:NSUTF8StringEncoding]];
            dispatch_async(task, ^{
                [outputStream write:[dataToSend bytes] maxLength:[dataToSend length]];
            });
        }
    }
    [inputStream close];
    [outputStream close];
    inputStream = nil;
    outputStream = nil;
    [inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    initializedSocket = NO;

    [FlurryAds setAdDelegate:nil];
}

I am getting an EXC_BAD_ACCESS on the ouputStream write method. I am attaching screenshots as well. Image

  • 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-17T17:01:19+00:00Added an answer on June 17, 2026 at 5:01 pm

    Looks like a dangling pointer.

    The stream is being referenced in an ivar, and so your dispatched block only retains self, not self->outputStream. When you clear the ivar just after the block is dispatched, the only strong reference to it is gone and the stream is deallocated while still in use, resulting in a crash.

    To avoid the problem, ensure that your block maintains a strong reference to the stream by using a locally-scoped variable instead of an ivar:

    NSOutputStream *os = self->outputStream;
    dispatch_async
    (
        ...,
        ^ {
            [os write:...];
        }
    );
    

    Note that creating a dispatch queue here for this one block is not meaningful; you should just use the global queue.

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

Sidebar

Related Questions

Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I am getting an error which I have no idea how to fix. I
Getting error when its casting in Listview: private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
Here's the whole error I keep getting from xerces.... When <simpleContent> is used, the
Getting Django to send an email is nicely explained here using standard settings as
Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have
Getting 'Dispatcher has no subscribers' error while trying to post message to a channel
Getting a strange error when trying to insert data into an Access database using
I have a progressDialog. The spinner in the progressDialog has to spin and it
Getting the following error: "Warning: Cannot modify header information - headers already sent by

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.