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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:16:55+00:00 2026-05-28T03:16:55+00:00

Can anyone please help with ARC and memory-related crashes? I have class LTRequest with

  • 0

Can anyone please help with ARC and memory-related crashes?

I have class LTRequest with a member variable that stores a block pointer:

typedef void (^APICallOKBlock)(id);

@interface LTRequest : NSObject
@property (nonatomic, strong) APICallOKBlock okCB;
@end

The code to initialize that variable:

-(void)addOKBlock:(APICallOKBlock)okBlock
{
    self.okCB = okBlock;
}

I call the block in case of success:

-(void)apiCallCompletedWithResult:(id)result
{
    if(self.okCB != nil)
    {
        self.okCB(result);
    }
}

For reference, the block looks something like this:

APICallOKBlock okBlock = ^(id result)
{
    [self handleAPICallCompleted:result];
};

It calls a function defined in the object that scheduled the api call, however that part is not important. Important is what happens when apiCallCompletedWithResult is called after the api call has been successful. And what happens is that the block gets called but the app crashes shortly afterwards when the request object LTRequest gets deallocated (SomeAppName is our application):

Thread 6 name:  Dispatch queue: com.apple.root.low-priority
Thread 6 Crashed:
0   libobjc.A.dylib                 0x300bad9c objc_release + 12
1   libobjc.A.dylib                 0x300c6c00 objc_storeStrong + 24
2   SomeAppName                     0x00055688 -[LTRequest .cxx_destruct] (LTRequest.m:12)
3   libobjc.A.dylib                 0x300bba66 object_cxxDestructFromClass + 50
4   libobjc.A.dylib                 0x300bba2c object_cxxDestruct + 8
5   libobjc.A.dylib                 0x300b99ac objc_destructInstance + 20

I tried to use unsafe_unretained instead of strong to store the block in the LTRequest object:

@property (nonatomic, unsafe_unretained) APICallOKBlock okCB;

In that case the crash happens exactly in the line with the if:

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x300b9eda objc_retain + 10
1   libobjc.A.dylib                 0x300c6bde objc_retainAutoreleasedReturnValue + 34
2   SomeAppName                     0x00054f90 -[LTRequest apiCallCompletedWithResult:] (LTRequest.m:84)
3   SomeAppName                     0x0002f8aa __29-[LTServerProxy makeAPICall:]_block_invoke_0 (LTServerProxy.m:154)

// file LTRequest.m

line 84    if(self.okCB != nil)
line 85    {
line 86        self.okCB(result);
line 87    }

Am I using the pointer to a block properly and how should I call it to not cause any crashes?

Some info: I am using iOS SDK 5.0, deployment target is 4.0, device iPhone, and ARC is enabled for the whole project.

  • 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-28T03:16:56+00:00Added an answer on May 28, 2026 at 3:16 am

    You want the property to be copy rather than retain:

    @property (nonatomic, copy) APICallOKBlock okCB;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please help me. I have developed macro that keeps track of huge
Can anyone please help me with this? I have a Windows 2008 server and
can anyone please help me with this query. I have a CSV file which
Can anyone please help me with compiling servlet? Do I have to include path
Can anyone please help in finding the solution of the above question I have
Update: How to create a out variable?Can anyone please help me find out what
Can anyone please help me on the following: I have created a SQL Server
Can anyone please help me to work out how to achieve the following? I
Can anyone please help me to add video controls (play, pause, forward, seekbar) to
Can we add image together with text in a picker view? Anyone please help!

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.