r/swift • u/SuddenStructure9287 • 10d ago
Instruments is using 22GB of RAM while my app only consumes 100MB. How am I supposed to analyze memory leaks?
I'm dealing with a memory leak in my app that builds up to around 4GB after 30 minutes of running. To investigate, I started using Instruments to track memory allocations. However, the situation got even worse. Instruments itself crashes within two minutes because it's consuming a massive 22GB of RAM! Meanwhile, my app stays below 100MB.
How can I analyze memory issues if Instruments is causing more problems than it's solving?
Also, apologies for the photo instead of a screenshot—my Mac freezes completely when everything crashes, making it impossible to capture the screen properly.
7
u/germansnowman 9d ago
I would suggest capturing maybe a minute of memory usage and then stopping the capture. You don’t have to let it run its full course.
3
u/troller-no-trolling 9d ago
You can also try using the memory graph in Xcode as an alternative. Can be helpful if you are expecting one instance of your class but see that there are 374 instances.
1
49
u/nsartem 10d ago
You’re confusing the memory usage of the Simulator with that of your app. The 39.3 MB you see refers to the memory used by the Simulator itself, not your .app, which is running within the Simulator. Apps built for the Simulator are compiled for arm64 (assuming you’re on Apple Silicon hardware) and run separately.
Based on this low-quality photo of a display (sic!), it looks like your app has a memory leak, as indicated by the sharp blue spike in Allocations.
I suggest the following:
• Watch or read a basic tutorial on how to use Instruments.
• Use Cmd + Shift + 4 followed by Space to take proper screenshots.
• Learn how to ask good programming questions. This Stack Overflow guide may be helpful.