dmytro-anokhin / url-image

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.
MIT License
1.1k stars 96 forks source link

{Bug} Fatal Exception: NSMallocException Failed to grow buffer #152

Closed IvanShah closed 3 years ago

IvanShah commented 3 years ago

Hello, we are facing several issues in our Crashlytics, it looks like an issue when there is not enough memory on the device, we support only devices with iOS 14+, full log:

Fatal Exception: NSMallocException 0 CoreFoundation 0x1999ef9d8 exceptionPreprocess 1 libobjc.A.dylib 0x1add72b54 objc_exception_throw 2 CoreFoundation 0x199a5ee1c -[NSInvocation retainArguments].cold.1 3 CoreFoundation 0x199a56b30 CFReallocationFailed 4 CoreFoundation 0x19990c468 CFSafelyReallocate 5 CoreFoundation 0x199930e20 CFDataGrow 6 CoreFoundation 0x199930c30 CFDataSetLength 7 CoreGraphics 0x19b2ceb60 CGDataProviderCopyData 8 ImageIO 0x19af80324 IIOImageRead::CreateWithDataProvider(CGDataProvider, bool) 9 ImageIO 0x19af82ee4 CGImageReadCreateWithProvider 10 ImageIO 0x19aebcb54 IIOImageSource::updateDataProvider(CGDataProvider, bool) 11 ImageIO 0x19aec1714 CGImageSourceUpdateDataProvider 12 App 0x104bae658 ImageDecoder.allocatinginit(url:) 13 App 0x104b901ec closure #1 in closure #1 in DiskCache.getImage(withIdentifier:orURL:maxPixelSize::) 14 App 0x104b98bfc thunk for @escaping @callee_guaranteed () -> () 15 Foundation 0x19aca22e8 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK 16 Foundation 0x19ab9f098 -[NSBlockOperation main] 17 Foundation 0x19aca45a0 __NSOPERATION_IS_INVOKING_MAIN 18 Foundation 0x19ab9ed54 -[NSOperation start] 19 Foundation 0x19aca4f98 NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION 20 Foundation 0x19aca4a64 __NSOQSchedule_f 21 libdispatch.dylib 0x1995d775c _dispatch_block_async_invoke2 22 libdispatch.dylib 0x199628280 _dispatch_client_callout 23 libdispatch.dylib 0x1995cd390 _dispatch_continuation_pop$VARIANT$mp 24 libdispatch.dylib 0x1995ccad4 _dispatch_async_redirect_invoke 25 libdispatch.dylib 0x1995d9f3c _dispatch_root_queue_drain 26 libdispatch.dylib 0x1995da704 _dispatch_worker_thread2 27 libsystem_pthread.dylib 0x1e155d568 _pthread_wqthread 28 libsystem_pthread.dylib 0x1e1560874 start_wqthread

dmytro-anokhin commented 3 years ago

Hey, this seems like old version of the package. Have you tried updating to v3? In v3 you can disable in memory cache and rely on system cache. This potentially will decrease memory consumption.

However, if you're running out of memory, I think this is more on the app side to profile with Instruments and see what resources can be released.

IvanShah commented 3 years ago

Thank you, I'll update the package and try the system cache, memory problems appear only when images are in the process of loading

dmytro-anokhin commented 3 years ago

One more thing to mention about v3 is that images are decoded lazily. This should give more time for the system to free resources. You can also specify lower maxPixelSize value to reduce memory footprint of the final image.

IvanShah commented 3 years ago

After update memory problem solved, thank you