Search code examples
xcodeinstrumentsxcode-instruments

Xcode Instruments error: Allocations tracking library was not loaded in time


When profiling a standalone application target using Instruments with the allocations instrument, the following happens.

  1. Start the recording
  2. The application starts up right away
  3. Instruments shows a beach ball for about ~10 seconds
  4. The application is closed and Instruments displays an error message

Error: Allocations tracking library was not loaded in time.

enter image description here


Solution

  • The error happens because Instruments must inject a runtime library into the binary being profiled. To do so, Instruments uses environment variables meant for DYLD to inject said library. Recent versions of macOS have new security measures which prevent that type of injection.

    In order to work around this problem, the project needs to be configured with additional "entitlements". To do so, follow these steps:

    1. Open your Xcode project
    2. Display the left pane
    3. Select the Project Navigator tab
    4. Select your project
    5. In the main pane, select the Signing & capabilities tab
    6. In the Hardened Runtime section, enable the Allow DYLD Environment Variables entitlement
    7. Rebuild
    8. Profile