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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:23:32+00:00 2026-05-18T09:23:32+00:00

I think there is something i did not understand in the memory management in

  • 0

I think there is something i did not understand in the memory management in xcode and when to or not to release objects to avoid memory leaks. I have been reading this presentation, but since there is no audio i dont understand all the sides: http://www.slideshare.net/OwenGoss/finding-and-fixing-memory-leaks-in-ios-apps-5251292

Here is a very simple code of my app that is the issue:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

 NSString *myBundleName = [[NSString alloc] init];
 NSString *myBundleVersion = [[NSString alloc] init];
 NSString *myBundleBuild = [[NSString alloc] init];
 NSString *myIosName = [[NSString alloc] init];
 NSString *myIosVersion = [[NSString alloc] init];

 myBundleName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
 myBundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
 myBundleBuild = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
 myIosName = [[UIDevice currentDevice] systemName ];
 myIosVersion = [[UIDevice currentDevice] systemVersion];

 self.versionBuildLabel.text = [NSString stringWithFormat:@"%@ version %@ build %@ on %@ %@", myBundleName, myBundleVersion, myBundleBuild, myIosName, myIosVersion];

 [myBundleName release];
 [myBundleVersion release];
 [myBundleBuild release];
 [myIosName release];
 [myIosVersion release];

}

If I try to run this

 [myBundleName release];
 [myBundleVersion release];
 [myBundleBuild release];
 [myIosName release];
 [myIosVersion release];

Then the application crashes with

[Session started at 2010-12-02 14:08:47 +0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1472) (Wed Jul 21 10:53:12 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
sharedlibrary apply-load-rules all
Attaching to process 26707.
Pending breakpoint 1 - ""HomeVC.m":49" resolved
(gdb) continue
Current language:  auto; currently objective-c
[Switching to process 26707]
[Switching to process 26707]
Program received signal:  “EXC_BAD_ACCESS”.
(gdb) 

I thought i was doing the right thing by releasing intermediate variables used to make my code easier to understand.

What is the problem here?

NB: I face similar problems in other portion of my code, but this is the simplest example that causes me problems, for which there is probably a notion i did not understand.

  • 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-18T09:23:33+00:00Added an answer on May 18, 2026 at 9:23 am

    When you assign your variables with items from [UIDevice currentDevice] and [NSBundle mainBundle], those objects come autoreleased. Since they’re autoreleased, iOS automatically handles memory management of those objects for you. That’s why your app crashes when you try to manually release them.

    Don’t initialize your NSStrings to new objects (i.e. [[NSString alloc] init]). Initialize them with the convenience methods right away:

    NSString *myBundleName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
    NSString *myBundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
    NSString *myBundleBuild = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
    NSString *myIosName = [[UIDevice currentDevice] systemName];
    NSString *myIosVersion = [[UIDevice currentDevice] systemVersion];
    

    And don’t call release on any of them. This way your method never has ownership of these objects; they just happen to be passed to it for use.

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

Sidebar

Related Questions

I think there is something I don't understand about same origin limitation for XMLHttpRequest
jQuery-selectable is causing memory leaks. How can I prevent this? Is there something I
I'm having trouble using newly installed gems - I think there must be something
Edit I think there is some confusion, I am not using both of the
I've been using the search function but I think there isn't any related question
Using the release version of Visual Studio 2010 I think there's a difference in
I have a large web app, and I think there are a bunch of
I'm using guidelines right now, but I do not think there is any way
There is something that I cannot understand in C#. You can cast an out-of-range
If there were such a thing I would imagine the syntax to be something

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.