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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:40:14+00:00 2026-06-04T06:40:14+00:00

I’m using RestKit to download several files in my app. As long as the

  • 0

I’m using RestKit to download several files in my app. As long as the files aren’t too big everything works like a charm. Unfortunately I’ve tried downloading a big video file (around 230 MB) and get a memory warning and the app crashes.

I start the download with the following line

[[RKClient sharedClient] get:[NSString stringWithFormat:@"/%@", listItem.filename] delegate:self];

In the delegate method I save it localy in appDirectory/Library/Caches/

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
{
    NSURL * url = [NSURL fileURLWithPath:[cacheDirectory stringByAppendingPathComponent:response.URL.lastPathComponent]];

    [[response body] writeToURL:url atomically:YES];
}

I’ve checked the app in Instruments for memory leaks and saw that Live Bytes for *Overall Allocations* kept rising up before the Low Memory Alerts came at around 100 MB. There were no leaks though.

Removing the line that’s responsible for saving the file ([[response body] writeToURL:url atomically:YES];) didn’t change anything, so I guess the problem is somewhere in RestKit.

While researching I stumbled upon a method of ASIHTTPRequest which allows direct file download and thought something like that could solve the issue, not sure though.

Is there possibility in RestKit for direct downloading that I missed?

or

Is there a better way to download files with RestKit that I should know of?

  • 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-04T06:40:15+00:00Added an answer on June 4, 2026 at 6:40 am

    I encountered the same problem, unfortunately I don’t think there is a way around other than modifying your local RestKit copy. The problem is located in - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data, exactly in [_body appendData:data];. As you can see, RestKit keeps the body of the response in the memory and appends the bytes as they are sent from the server. This is why you get low memory warnings. My solution was to add a property to RKRequest and write data directly to file system depending if the request is a big file request or not:

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    if ([_request dontKeepBytesInMemory]) {
        if ([[_request delegate] respondsToSelector:@selector(request:didReceivedData:totalBytesExectedToReceive:)]) {
            [[_request delegate] request:_request didReceivedData:data totalBytesExectedToReceive:_httpURLResponse.expectedContentLength];
        }
    } else {
        [_body appendData:data];
        if ([[_request delegate] respondsToSelector:@selector(request:didReceivedData:totalBytesReceived:totalBytesExectedToReceive:)]) {
            [[_request delegate] request:_request didReceivedData:[data length] totalBytesReceived:[_body length] totalBytesExectedToReceive:_httpURLResponse.expectedContentLength];
        }
    }
    

    }

    I also needed additional RKRequest delegate method in the protocol, so I could process the big responses separately. The original delegate method defines totalBytesReceived which is simply the [_body length], but if you write bytes directly to file system you can just check the current file size to track the download status. If you are looking for a good way to save bytes directly to file system, take a look at NSFileHandle class – it supports file offset so you can just throw any NSData at it and it will automatically append it for you.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
For some reason, after submitting a string like this Jack’s Spindle from a text

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.