Getting different data in Instruments based on method of profiling

那年仲夏 提交于 2019-12-11 06:02:12

问题


This question is a follow up question to the answer of this: instruments-leaks-and-allocations-tvos

The initial question relates to a memory leak I had in a tvOS app, but I think the answer to this question is relevant to iOS/Xcode/Instruments development in general.

The issue was solved by removing a closure inside another closure keeping a reference to a variable in the first closure. This caused a retain cycle.

Question

I really want to understand why I didn't find the issue earlier, let me explain.

How it turned out, I used Instruments the wrong way. My workflow while profiling was the following:

  • From Xcode, I Run the app on the Apple TV device
  • Start up Instruments
  • Attach Instruments it to the launched app

The following was visible in Instruments:

There were some leaks, but nothing that special. The graph didn’t really increase, not even after an hour. I used this method for a long time, and never thought something could be wrong here.

While reading about leaks, profiling etc. I came across some random article where someone was using the Profile button from Xcode (instead of Run). I just thought this was doing the same I was doing: Running the app, starting Instruments and attaching the process. But, magically, this graph appeared:

Clearly there is a memory leak here and using this data, finding the leak was pretty easy to do.

So I really want to know what is the difference between these 2 approaches, but I can't make anything out of it. Anyone :) ?

PS: The screenshots were made 2 minutes after each other with exactly the same codebase, just a different way of connecting Instruments to the process.


回答1:


The difference between the two approaches is when you choose Profile from Xcode, Instruments records all the memory allocations from the start. When you run the app in Xcode, launch Instruments, and attach the app, you're going to miss all the memory allocations that occurred before you attached the app to Instruments. Choosing Profile from Xcode is the better option if you want to record every memory allocation your app makes because it starts recording from app launch.

To answer your question about why Instruments has different data when you choose Run and Profile in Xcode, I suspect it's because they run different builds of your app. Xcode is initially set to use the Debug build configuration when you choose Run in Xcode and set to use the Release build configuration when you choose Profile. Instruments can show different memory usage for debug and release builds. You can edit your scheme to see the build configurations used for running and profiling.



来源:https://stackoverflow.com/questions/43388395/getting-different-data-in-instruments-based-on-method-of-profiling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!