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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:26:01+00:00 2026-06-14T23:26:01+00:00

I try to write a program in Objective C that calculates some stuff. Unfortunately

  • 0

I try to write a program in Objective C that calculates some stuff. Unfortunately there is a lot to calculate and the Program is running a loop with 10000 iterations. The total running time is around 5 minutes.
This isn’t an issue but while it is running the memory the program uses goes up dramatically (above to 2GB) and I figure it is because of some Values that are not released. I narrowed the problem down to a creation of a NSArray inside a loop. The problematic code (changed it to concentrate on the problem) is this:

for (NSInteger k = 0; k<100000; k++) {

    NSMutableArray *mutableTestArray = [NSMutableArray new];
    for (NSInteger i=0; i<200; i++){

        NSMutableArray *subArray = [NSMutableArray new];
        for (NSInteger j=0; j<200; j++) {

            //simplified version, normally the valus for sub array are dependent on some other factors
            [subArray addObject:[NSArray arrayWithObjects:@"test", @"test", nil]];

        }
        [mutableTestArray addObject:subArray];

    }


    //do stuff with mutableTestArray
    //change parameters that go into sub array

}

If I replace:

[subArray addObject:[NSArray arrayWithObjects:@"test", @"test", nil]];

with:

[subArray addObject:@"test"];

it works fine. So I guess I somehow have to release the Array I created. But how?
I have ARC enabled and as far as I know if it is enabled I can’t release objects manually. It would be great if someone could help me with how to change the code or hint me somewhere where I can learn how to do memory management correctly.

Thanks

  • 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-14T23:26:03+00:00Added an answer on June 14, 2026 at 11:26 pm

    Just throw in some autoreleasepools :

    @autoreleasepool {
            NSMutableArray *subArray = [NSMutableArray new];
            for (NSInteger j=0; j<200; j++) {
    @autoreleasepool {
    
                //simplified version, normally the valus for sub array are dependent on some other factors
                [subArray addObject:[NSArray arrayWithObjects:@"test", @"test", nil]];
    }
            }
            [mutableTestArray addObject:subArray];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: Write a program that prompts the user to enter some number of 1,
I want to write a program, which search some HTML addresses. I assume that
I'm thinking of using Java to write a program that I might try to
I try to write a program that shows an additional (task)bar on the top
I am try to write a program that will accept a sequence of names
I got home yesterday and decided to try and write a scheme program that
I try to write a simple OCaml program that returns true if the a
I am trying to write a program in Python that will loop to keep
I thought I would try and write a program that would paint a ball,
I'm helping to write a program that manages VMs remotely. When I try to

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.