Mac OS: Leaks Sanitizer

前端 未结 2 477
忘了有多久
忘了有多久 2021-01-03 01:38

Mac OS X Sierra 10.13

I do as wrote here https://clang.llvm.org/docs/LeakSanitizer.html

I.e. created the small application with memory leak

#         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 02:10

    Note that you can also use the Leaks Instrument which ships with Xcode to find leaks in your code without having to install anything extra. It's not very well advertised, but it's a very useful tool. From the "Product" menu, choose "Profile". This may rebuild your application, and it will then launch the Instruments.app. You'll be presented with a sheet of different profiling instruments you can use like this:

    Once you choose it and press the "record" button, it will run your app and display a track showing you any leaks, like this:

    A green check means no leaks in the app at that time. A red "x" means a new leak since the last check. A gray "-" means there are leaks, but no new ones since the last check. The default is to check every 10 seconds.

    At the bottom is a list of the current leaks. If you click on one, you'll see a stack trace on the right showing which function allocated the leaked memory.

    This is a very powerful tool that has almost no documentation! I'm not sure why Apple keeps it so hidden.

提交回复
热议问题