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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:43:58+00:00 2026-06-04T01:43:58+00:00

I have turned of Automatic Reference Counting (ARC) in my Xcode 4.3.2, and thought

  • 0

I have turned of Automatic Reference Counting (ARC) in my Xcode 4.3.2, and thought I was in good hands. Then I wrote this little program:

int main()
{
    int *a = new int(3);
    delete a;
    printf("%i",*a);
    return 0;
}

Which is printing 3, but it should print garbage. It looks like the compiler takes care of all my memory allocations, which I don’t want it to do. What do I have to do to remove that?

  • 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-04T01:43:59+00:00Added an answer on June 4, 2026 at 1:43 am

    You give your program an address on the heap with new. It happens to be an integer with the value 3 at that address.
    When you free that heap area with delete, it is not immediately set to some garbage value, it still contains 3.
    Your print statement goes to the address at a and tries to print the integer that is there, it finds 3 and prints it.

    You could try adding compiler warnings if this is possible in xcode, I know gcc and other command line compilers offer this feature, to avoid these confusing undefined behaviors from occurring with out the program yelling at you.

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

Sidebar

Related Questions

I have turned computer monitor off using this command SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)(turnOff ?
(Before anyone says anything Yes this was homework but i have already turned it
I have a radcombobox with checkboxes turned on. I wrote a jQuery script to
I have a text box that I have turned on HTML rendering for. This
I have turned on warnings as errors and now i need to XML comment
I have turned a normal PHP class into a library so I can use
I have turned off lazy loading and the proxy creation on my DbContext. I
CFMX 8 Enterprise I have turned on the Use J2EE session variables setting under
I run an ASP.NET application on IIS 6.0. Usually I have compression turned on
I have http compression turned on in my production IIS box. Is there a

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.