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

The Archive Base Latest Questions

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

I am currently trying to work myself into iOS development. Right now I’m having

  • 0

I am currently trying to work myself into iOS development. Right now I’m having trouble understanding memory management.
This is the cause of my confusion:

NSString *path = [self.dataPath stringByAppendingPathComponent:@"dummy.plist"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSString *dummyKeyValue = [dict valueForKey:@"dummyKey"];

// NSLog(@"%@",[NSString stringWithString:dummyKeyValue]);

[dict release];

NSString *anotherString = [dummyKeyValue lowercaseString];

This piece of code triggers an EXC_BAD_ACCESS error on the last line. Seemingly because NSDictionary releases its key values. What I don’t understand is why the dummyKeyValue definition is not being taken into account, because obviously dummyKeyValue is still pointing to the value of "dummyKey".

Now the next problem and even funnier phenomenon occurs when you comment out the NSLog line. Using dummyKeyValue in one way or another seems to prevent the release of the memory it points to. WHY?

Help is appreciated!

  • 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-17T16:18:27+00:00Added an answer on June 17, 2026 at 4:18 pm

    In manual reference counting mode, simply defining a variable doesn’t mean that the object the variable points to will automatically be kept around. When dict is released, it releases its value objects, and if there are no other objects with a strong reference to them (i.e. their reference count is now 0), they are released. That’s what you appear to be seeing here.

    If you want to keep a strong reference to dummyKeyValue, you need to retain it after receiving it. Of course, that also means you need to release it when you’re done with it. Try this:

    NSString *dummyKeyValue = [[[dict valueForKey:@"dummyKey"] retain] autorelease];
    

    Now dummyKeyValue will stick around until the end of the current autorelease pool scope. Often, accessor methods are written to do just this before returning a value to avoid exactly the situation you’re seeing.

    Worth noting is that if you were using ARC (Automatic Reference Counting), you wouldn’t have this problem as the compiler would insert the necessary retain/release calls to ensure that dummyKeyValue stuck around until you were done with it.

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

Sidebar

Related Questions

I am having trouble getting my application to work correctly. I am trying to
I am currently trying to work with ImageMagick and teaching myself as I go.
I'm a new programmer trying to teach myself C++ and OOP. Right now I'm
I ask this because I am currently trying to work out my own technique,
Hey all, here is the issue I am currently trying to work through. We
I'm currently trying to get ActiveAdmin to work on a model of mine but
Erlang version: R13B01 Currently I'm struggling trying to make Erlang work with SSL. The
I am currently trying to teach myself C++ and programming in general. So as
I'm currently trying to create a custom navigation-bar for my navigation-controller in iOS using
I'm trying myself developing a desktop application with Java and Java Swing. Currently I'm

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.