- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 333字
- 2021-07-02 14:45:06
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:

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.
- 計(jì)算機(jī)組成原理與接口技術(shù):基于MIPS架構(gòu)實(shí)驗(yàn)教程(第2版)
- PyTorch深度學(xué)習(xí)實(shí)戰(zhàn):從新手小白到數(shù)據(jù)科學(xué)家
- 數(shù)據(jù)分析實(shí)戰(zhàn):基于EXCEL和SPSS系列工具的實(shí)踐
- Voice Application Development for Android
- Python廣告數(shù)據(jù)挖掘與分析實(shí)戰(zhàn)
- 醫(yī)療大數(shù)據(jù)挖掘與可視化
- 深入淺出MySQL:數(shù)據(jù)庫開發(fā)、優(yōu)化與管理維護(hù)(第2版)
- 大數(shù)據(jù)Hadoop 3.X分布式處理實(shí)戰(zhàn)
- 中國數(shù)字流域
- Starling Game Development Essentials
- 白話大數(shù)據(jù)與機(jī)器學(xué)習(xí)
- SQL應(yīng)用及誤區(qū)分析
- 編寫有效用例
- 數(shù)據(jù)挖掘競賽實(shí)戰(zhàn):方法與案例
- 大數(shù)據(jù)計(jì)算系統(tǒng)原理、技術(shù)與應(yīng)用