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

  • Home
  • SEARCH
  • 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 7833059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:32:59+00:00 2026-06-02T12:32:59+00:00

I have a retain/release project that has a simple algorithm. I start out w/

  • 0

I have a retain/release project that has a simple algorithm. I start out w/ a 100000 objects mutable array and every 5 seconds interval I remove 1000 objects at the beginning and add 1000 objects at the end. In theory my memory footprint should stay the same after a lil delay, however it consistently rises until it caps out at a certain amount. But removing all its objects with “[array removeAllObjects]” and releasing the array doesn’t reclaim all the memory back, just a portion. I am running in release scheme, with no debugger, and using the activity monitor to track memory usage.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
    array = [[NSMutableArray alloc] init];
    for(int i = 0; i<100000; i++){
        NSURL *url = [NSURL URLWithString:@"http://www.apple.com"];
        [array addObject:url];
    }
    self.t = [NSTimer scheduledTimerWithTimeInterval:10  target:self selector:@selector(addAndRemove:) userInfo:nil repeats:YES];

}

-(IBAction)addAndRemove:(id)sender{
     [array removeObjectsInRange:NSMakeRange(0, 1000)];

     for(int i = 0; i<1000; i++){
        NSURL *url = [NSURL URLWithString:@"http://www.apple.com"];
        [array addObject:url];
     }
}

-(IBAction)clear:(id)sender {
    [array removeAllObjects];    
    [array release];
    [t invalidate];
    t = nil;
}
  • 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-02T12:33:02+00:00Added an answer on June 2, 2026 at 12:33 pm

    Monitoring your memory usage with Activity Monitor is pretty unreliable. First, which memory field are you watching (Virtual Private Memory, Real Private Memory, Real Shared Memory, or Real Memory)?

    Second, when your code makes an allocation request, that typically goes, directly or indirectly, to the malloc routines. The malloc routines try to satisfy your request from the memory that it already has. If it can’t then it requests more from the system. When you free memory, it goes back to malloc. Malloc does not necessarily return it to the system. It may keep it to more quickly satisfy future requests. So, you may not see your process’s memory usage go down, at least not all the way, even if your program is releasing everything it allocated.

    The proper way to check that your program is managing memory correctly is to use Instruments with the Leaks and Allocations tools.

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

Sidebar

Related Questions

I have one array. I want that array to retain its value between function
I have a simple project to present a modal view controller and transfer back
I have the following piece of code. I am a bit unsure about retain/release
I have a global dictionary with Class objects and NSString keys. Every custom subclass
I am trying to get the hang of retain / release. I get that
If I create a String with [NSString StringWithFormat], do I have to [retain] it?
I have a problem. There are two classes: struct Base { Base* retain() {
I have a variable declared like this: @property (nonatomic, retain) NSMutableArray *aInfo; At the
Do I have this right ... // Reactor.h @property(nonatomic, retain) NSMutableArray *reactorCore; // Reactor.m
I have a c++ process, I want that process should always remain on foreground,

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.