简体   繁体   中英

Memory issue with large NSData

I was reading a really large file into memory on the main thread (not just the simple dataWithContentsOfFile: method, I was also doing some data manipulation), and my app crashed. After I moved this process to a background thread, the app doesn't crash anymore. The only thing that happens is that the NSData I get is nil .

Is it possible that only my background thread is interrupted without affecting the main thread, or am I missing something? Also, can I count on this behaviour and just display an error message when the NSData is nil , without the app to crash? Thank you in advance.

Edit:

The log I get is:

malloc: * mmap(size=629800960) failed (error code=12) error: can't allocate region * * set a breakpoint in malloc_error_break to debug

The file I was using is about 250 MB large.

I know why it crashed on the main thread. My question is, why didn't it crash on a secondary thread?

I guess it can depend on the crash, but if it is a problem of lack of memory (you can both be using too much memory or be creating too many objects) it will crash the entire app.

You should try to test the app with smaller files and see how it behaves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM