Quote:
Originally Posted by edster
Time to circle back on an issue I thought was long resolved. Back when I first did this, it seemed like the explicit init and release was doing the trick. However, I'm getting some crash reports from an old iTouch user where they are running out of memory.
So now I'm testing again and I'm seeing a huge spike in memory usage when its calculating the hash. Not doing the MD5 check, my app stays around 9.5 - 11MB for its entire life, while downloading as much as 200-300MB in the background. If I enable the MD5 check, memory will shoot up as high as 60MB or so which will kill old devices. Even after the spike, the memory seems to be creeping up over time even though 'Leaks' is not showing any memory leaking. So regardless of the memory spike, I think the hash routines are not freeing some allocated memory.
|
Even though you use a non autoreleased object called fileData, you still have an autoreleased object there:
Code:
NSData *fileData = [[NSData alloc] initWithData:[handle readDataOfLength:4096]];
Remember that the result of -readDataOfLength: was allocated and autoreleased. So, in reality, your solution is worse than the one proposed by smithdale87, because you end up allocating the same objects, plus one.
I came up with an implementation that really works. I wrote an article about this
efficient way to compute the MD5 hash of a large file.
I hope this helps.