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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:03:19+00:00 2026-06-05T18:03:19+00:00

App I’m working on uses ARC. I wanted it to process large files, so

  • 0

App I’m working on uses ARC. I wanted it to process large files, so instead of loading files as a whole, I’m loading chunks of data using NSFileHandle readDataOfLength method. It’s happening inside a loop which repeats until the whole file is processed:

- (NSString*)doStuff { // called with NSInvocationOperation

    // now we open the file itself

    NSFileHandle *fileHandle =
    [NSFileHandle fileHandleForReadingFromURL:self.path
                                        error:nil];

    ...

    BOOL done = NO;
    while(!done) {

        NSData *fileData = [fileHandle readDataOfLength: CHUNK_SIZE];

        ...

        if ( [fileData length] == 0 ) done = YES;

        ...

    }

    ...

}

According to profiler, there are no memory leaks; however, my app eats a LOT of memory while it processes the file. My guess — autorelease comes only after I process the file. Can I fix it without switching to manual memory management?

  • 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-05T18:03:20+00:00Added an answer on June 5, 2026 at 6:03 pm

    Wrap the code within that loop with a autorelease pool.

    while(!done) 
    {
        @autoreleasepool
        {
            NSData *fileData = [fileHandle readDataOfLength: CHUNK_SIZE];
            ...
            if ( [fileData length] == 0 ) 
            {
                done = YES;
            }
            ...                
        }
    };
    

    readDataOfLength retuns autoreleased data and since you stick inside that loop and therefor its method, that autoreleased data that does not get released until your loop and the encapsulating method is done.

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

Sidebar

Related Questions

My app pulls data from a website which uses Form based authentication. It needs
The app Im working on uses gps and sometimes in the onResume when the
App is in prism/mvvm/mef and uses loading by attribute like StockTraderRI. My shell window
My app, which uses ARC, does the following: Uploads a picture taken by the
My app uses LoadLibrary to load plugins at run-time and users can accidentally try
The app I'm working on is relatively simple but it is throwing memory warnings.
My app uses the android.support.v4.view.ViewPager class. For each page in the ViewPager, I want
My app is crashing using iOS5 and iOS4.3 iPhone simulators in Xcode 4.2, the
My app is slowed down by N+1 queries. I'm using the will_paginate gem with
We're building an app, our first using Rails 3, and we're having to build

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.