Search code examples
macoscocoainstrumentscfdata

Source of CFData (store) allocation at app start


At app start, my Cocoa app instantly creates two CFData objects. One of size 34 MB and another of size 57 MB. I cannot seem to figure out what these objects are or where they are coming from within Instruments.

Instruments

Both are allocated before applicationWillFinishLaunching completes.

I have tried clearing NSURLCache as well as clearing my Kingfisher image cache and am open to other ideas for cleaning out this data. How can I find the source of these allocations?


Solution

  • The issue turned out to be caused by NSUserDefaults. Earlier in development, I had saved some large files there, which were never deleted.

    Here is what the Instruments call tree revealed.

    Stack Trace

    From there I tried using

    NSUserDefaults.resetStandardUserDefaults()
    

    But that did nothing. Nor did cleaning my project or deleting the Derived Data folder manually.

    Following this answer brought my CFData allocation to zero: Clearing NSUserDefaults