Memory Footprint of SwiftUI custom Font in WidgetKit

I am building a widget for my app. Everything works as expected when using system fonts.

When I try to use the custom font for my app in the Text instances in my widget, the system shots down my WidgetKit extension because it runs against the 30MB memory limit for Widgets.

I have about 20 Text instances on my Widget. I initialize my font as a fileprivate global: let dinFont = Font.custom("AlteDIN1451Mittelschrift", size: 18)

Then I use Text("blah blah").font(dinFont) when I setup my labels.

When I only style a few text labels the widget renders fine. But when I try to use the font on all of them the widget extension is killed because of 30MB memory limit.

This sounds like, .font(dinFont) is creating a copy of the font instance. Is this the expected behavior?


Hi ekurutepe,

After reproducing the crash please use Feedback Assistant to report and issue (and please include the sysdiagnose it takes automatically). Once you do that, it'd be great to let us know the FA number here as well. Thank you!
I am encountering this as well. I filed FB8060728 with a sample project demonstrating the issue. I also attached sysdiagnose info.

It looks to me like this issue makes using custom fonts infeasible, so I hope it can be addressed. Thank you.

John
Accepted Answer
Thanks for filing the feedbacks and report them here. It should be addressed in the latest developer beta (3). Please check again.
Confirmed - beta 3 fixed this. Thank you!

It will be reproduced in the lock screen widget.

Memory Footprint of SwiftUI custom Font in WidgetKit
 
 
Q