-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encrypt/Decrypt large files will cause memory usage spike #129
Comments
I also tried to enwrap the block inside an autoreleasepool, but it doesn't work either. The following is the code I used, mostly the same as the Async and Streams section of ReadMe:
|
You may want to make that internal call dispatch_async(). I.e.: |
The other way would be to put in @autoreleasepool { ... } around the content in the dispatch_async() block in RNEncryptor's addData: method. It seems like with the above pattern, any objects autoreleased in there do not get released until the end of the process. But if the call to readStreamBlock() in the sample code above is made async (as the comment suggests it might be good to do), then the system autorelease pools get flushed more correctly. |
I think you need to use NSFileHandler to encrypt the file data by pieces, you can encrypt the piece data by [NSFileHandler seekTo...] to get pieces of data, and encrypt them, then you can append it to a file, also you can try NSOutputStream to write file. If you get the whole data, it will out of memory with no doubt. |
I believe the Swift version has more reliable memory usage, and no longer has a misleading example. |
For anyone coming in here via Google; I solved this problem by applying the semaphore solution suggested on Stack Overflow: Using code like that my iPad mini successfully encrypted a 2 GB file in one minute, with no memory issues. |
First of all, in the README, this line of code in "Async and Streams":
The variable name should be "encryptor".
Secondly, when trying out this code myself, I used a 1.9G huge file to test the memory issue. And the app will always crash due to memory spike.
I profiled it, and found that as the encryption goes, the memory usage keeps going up, never goes down.
After a closer look, I see that it's this call that increases memory usage every time for 48 KB:
So, I added a symbolic breakpoint for this function, and found that it's called by RNCryptorEngine.m at line 93 via
So, looks like when using the Async and Streams method in ReadMe to encrypt a file, the memory usage will keep going up due to unknown issues related to this line of code.
I'm not quite familiar with RNCryptor yet. Is this a bug of RNCryptor? How can I fix this issue
Thanks a lot!
The text was updated successfully, but these errors were encountered: