Serialize large files - store in memory or on disk? <p>I do a networking app using iPhones and their limited memory is something I must consider. My <code>Message</code> class holds both a image and a video. Now I am about to implement the video file transfer (image already implemented, and is working). I guess the image can be loaded to memory because of their relatively small size (1+ MB), but large video files must reside on disk to avoid filling the memory. </p> <p>To be able to encode the <code>Message</code> instance for sending it over the network (using <code>NSCoding</code> protocol), I convert the <code>UIImage</code> instance to NSData that resides in memory:</p> <pre><code> NSData *imageData = UIImagePNGRepresentation(self.image); </code></pre> <p>The video is stored on disk and is accessed by using an <code>NSURL videoURL</code>. The content of this url (the video file itself) should also be encoded, and it have to be converted to NSData as well. If I init an NSData instance with this url, the <code>videoData</code> will be loaded into and occupying all available space in memory...</p> <pre><code>NSData *videoData = [[NSData alloc] initWithContentsOfURL:videoURL]; </code></pre> <p>...(am I wrong?) so this must be accomplished using another technique.</p> <p>Should I send the <code>Message</code> instance (without the video) first, and then send the video separately using some unknown technique? Or maybe I did miss some conceptual steps here?</p>