Is there a way to detect the memory usage of a Swift application itself?

I want to let my Swift app (a macOS cocoa app) print an NSLog if its memory occupation exceeds 300MB.

For that sort of question I'd recommend apple dev forums or stackoverflow – find a few discussions like this or that and figure out what works best for you. Then schedule a timer that checks memory usage periodically (†), say, every second and NSLog appropriately.

† This will miss cases when memory usage grows and quickly shrinks before your timer can see it.

1 Like