One important think of SwiftUI image

Wing CHAN
2 min readSep 15, 2021

--

Chinese version

Today, I upgraded to Xcode 13, found itself in Xcode12 running normal widget, in Xcode 13 there are errors, spent several hours finally solved, record it.

This is the effect, the top and bottom of a photo of my own shadow!

When I run it on the physical device, Xcode 13 reports an error that the widget memory cannot be used more than 30mb

EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=30 MB, unused=0x0)

The actual memory usage is 58.8mb, but sometimes it only shows up to 30mb, so it doesn’t show the correct memory usage, which should be a problem with Xcode.

Try a compressed photo

Before compression
Photo 1: 17.3MB (6000 × 4000)
Photo 2: 19.7MB (6000 × 4000)
Memory usage: 58.8MB

After compression
Photo 1: 89KB (6000 × 4000)
Photo 2: 96kb (6000 × 4000)
Memory usage: ~ 30MB UP

The problem is still present after compression.

Try to reduce the size of the photo

Before
Photo 1: 17.3MB (6000 × 4000)
Photo 2: 19.7MB (6000 × 4000)
Memory usage: 58.8MB

After
Photo 1: 11KB (320 × 213)
Photo 2: 12kb (320 × 213)
Memory usage: 8MB

Successfully reduced memory usage to 8mb!

Conclusion

The size of the image is very important in affecting the amount of memory used.

--

--