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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:46:37+00:00 2026-05-21T17:46:37+00:00

i now this is a silly question, but i still have some poor understanding

  • 0

i now this is a silly question, but i still have some poor understanding about this case. It is about memory management and reference count, i have some doubt about how many reference count will increase if i use copy, alloc, and mutable copy. This is the code i have :

This is myController.h :

#import <UIKit/UIKit.h>


@interface myController : UIViewController {
NSMutableString *mutableStringCode;
}
@property (nonatomic, copy) NSMutableString *mutableStringCode;
@end

and this is myController.m

#import "myController.h"


@implementation myController

-(void)viewDidLoad{
    mutableStringCode = [[NSMutableStringCode alloc]init];
    [self refresh];

}


-(void)refresh{
    NSMutableString *myFileContents = [NSMutableString stringWithContentsOfFile:localPath encoding:NSUTF8StringEncoding error:&error];

    mutableStringCode = [myFileContents mutableCopy]; 

    //another code

    myFileContents = nil;
}


-(void)dealloc{
    [mutableStringCode release];

    [super dealloc];

}

@end

in this code, i have some doubts :
1. how many reference count increase in that mutableStringCode ?
2. is it a true way to set mutableStringCode property using copy not retain?
3. am i still have to alloc that mutableStringCode after i set it copy on property?

can some body describe it to me??
Thank you

  • 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-21T17:46:37+00:00Added an answer on May 21, 2026 at 5:46 pm
    • If you simply create an instance of the myController class, and then release it, everything will be fine. mutableStringCode will be created in viewDidLoad (if it will be called) and released in dealloc. It happens because alloc retains object.
    • Every time you call refresh, these things happen:
      • you create autoreleased mutable string myFileContents.
      • you copy it to mutableStringCode, retaining it (copy retains object).

    The main problem I see here is that during refresh you are not releasing already created mutableStringCode. So it stays retained in memory (it is usual memory leak).

    You can try to catch these types of memory leaks with Analyse or with Instruments’ Leaks tool.

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

Sidebar

Related Questions

This may be a silly question, but right now I have a rather large
Okay, Now admittedly this sounds like a silly question; But, I actually have a
Now this may seem like a silly question, but I need to know how
Maybe a silly question, but where do I fill in this URL? I have
Probably a silly question here but I have been trying to find this for
This is probably a silly question, but I'm following a videocast about Rails, right
Now, this may be a silly question but sometimes the terms Framework and API
Okay, this may be a silly question but I'm still on my path to
I'm working with Python and threads by some time, but I still have a
My question may be very silly but here it is. I went through this

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.