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

The Archive Base Latest Questions

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

I had a hard to track bug which only appeared in the Release build

  • 0

I had a hard to track bug which only appeared in the Release build of my app, but not in the Debug build. The relevant difference between the builds turned out to be that the Debug build was compiled without any compiler optimization, whereas the Release build was compiled with -O (the bug was reproducible on all other optimization settings as well). This is all on LLVM.

In my view controller I have a property self.basicInfoContainerView defined as:

@property (weak, nonatomic) IBOutlet UIView *basicInfoContainerView;

I then removed the subview from one view, and added it onto another.

[self.basicInfoContainerView removeFromSuperview];
[self.infoTextView addSubview:self.basicInfoContainerView];

Depending on the compiler optimization level, different things happened.

With optimization on: as soon as the view was removed from its superview, the view was deallocated and self.basicInfoContainerView was a zero’ed, and as a result was not added as a subview to the new view.

With optimization off: the subview was not immediately deallocated and was successfully added as a subview to the new view.

(When I changed the property storage qualifier to strong, the view survived in both cases, but even though that solved the problem, but that’s not really my question.)

I would love someone to help me understand what is really going on here. Why does weak not immediately release my view (and zero the pointer if retain count == 0) when compiler optimization is turned off?

  • 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-17T14:18:08+00:00Added an answer on June 17, 2026 at 2:18 pm

    It’s really not unusual to see non-optimized code that keeps extra local (and strong) references to objects. So your unoptimized code must have a local strong reference to this ‘basicInfoContainerView’. That reference stays in scope through the method, and isn’t being released probably until the method returns.

    This is really just an accident of sorts that is masking a real bug in your code. The fact of the matter is as soon as you do [self.basicInfoContainerView removeFromSuperview], you can’t expect that your basicInfoContainerView will survive, because you don’t have any explicit strong reference to that view any more.

    The way to fix this, of course, is to create an explicit strong reference to that view. Then you’ve made your intention clear to the compiler, and you should get the result you want whether the code is optimized or not:

    UIView *containerView = self.basicInfoContainerView
    // this local variable is that explicit strong reference you need
    
    [containerView removeFromSuperview];
    [self.infoTextView addSubview:containerView];
    
    // the compiler can/will release this view when the local variable
    // 'containerView' goes out of scope
    

    Hope that helps.

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

Sidebar

Related Questions

I had a hard time understand exactly what an observer pattern was, but I
I had a hard time coming up with a title for this question, but
I'm working with an old app that had hard coded columns for different locations,
I've already registered my app on Facebook developer and got an ID, but had
I've just had a hard time finding a bug in my PHP code described
I have had a hard disk failure which resulted in some files of a
This might be a simple question, but I've had a hard time pinning down
Did you ever had a bug in your code, you could not resolve? I
I've had a hard time sitting in front of UML and getting value out
I recently had a hard drive crashed and lost all of my source code.

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.