官术网_书友最值得收藏!

Using the memory graph hierarchy tool

Now that we've properly configured our project, let's take a look at the tool itself.

Let's use the following code, for the sake of having a simple, working command-line Hello World! application:

class Hello {
func world() {
print("Hello, World!")
}
}

let hello = Hello()
hello.world() // set a breakpoint here

The preceding code is pretty simple; it just prints Hello, World! in the console.

With a breakpoint set on the hello.world() line, run your program, and, in the Debug toolbar, hit the icon that looks like a graph. It will open the Memory Graph Hierarchy tool:

You can also access it from the debug navigator menu, as follows:

Voilà! We get the result shown in the following screenshot:

Grandiose memory debug tool

This is the grandiose memory debug tool. As with many tools within Xcode, the screen is split into three main components:

  • On the left, you have a list of all of the allocations that are still living in the process, and our single hello instance is currently selected
  • In the center, there's an interactive view of the memory, with the relations that our object has with other objects
  • On the right, there's the information panel for the selected object, with some details, and, most importantly, the stack that led to its allocation

There are two very useful shortcuts that are also presented in this screen, shown as follows:

The shortcuts are as follows:

  • The first icon, which looks like a book, jumps to the definition of the object
  • The second one prints the description in the debugger

This tool is very powerful, and it's very important to master it. It will ultimately help you to better understand how your applications and projects behave. While for the sake of demonstration we used very simple code examples, and they didn't yield any issues, in the next section, you'll see the most common issues that you may encounter while tracking down memory leaks.

主站蜘蛛池模板: 朝阳县| 宜宾县| 宣威市| 枣庄市| 三原县| 孟村| 巢湖市| 蓬溪县| 宿州市| 大同县| 山西省| 塘沽区| 阿勒泰市| 上犹县| 客服| 独山县| 惠州市| 乡宁县| 定陶县| 盘锦市| 玉门市| 文登市| 延长县| 丰城市| 分宜县| 兰考县| 托里县| 平舆县| 牙克石市| 南江县| 鹤山市| 平谷区| 镇江市| 陈巴尔虎旗| 宁阳县| 睢宁县| 西贡区| 会宁县| 通江县| 仲巴县| 承德县|