You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UserDefaults caches its contents in memory, and loads it on application startup even if it's not used. This is vaguely documented.
From the docs:
UserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value.
Let's do an experiment to confirm that.
Let's make a very simple app based on the single view app template.
Before doing anything, let's record how much memory does our app consumes before any UserDefaults-related work.
On the iPhone SE 2 simulator: 8.7 MB.
Good. Let's save 100 MB of data to UserDefaults and see what we get.
(Originally published 2020-05-22)
UserDefaults
caches its contents in memory, and loads it on application startup even if it's not used. This is vaguely documented.From the docs:
Let's do an experiment to confirm that.
Let's make a very simple app based on the single view app template.
Before doing anything, let's record how much memory does our app consumes before any
UserDefaults
-related work.On the iPhone SE 2 simulator: 8.7 MB.
Good. Let's save 100 MB of data to
UserDefaults
and see what we get.After running that I got: 104 MB.
OK, let's run again removing that code; essentially like our very first run, and see if anything changes.
Now we got: 104 MB.
So, even if we no longer save or read from
UserDefaults
, just having that data there makes our app consumes what that data worth in memory.Code for the experiment.
The text was updated successfully, but these errors were encountered: