I am analyzing the differences between value types and reference types in terms of memory allocation, stack vs heap vs it depends for structs. One of the tools I use to determine whether a value is placed on the stack or heap is Xcode’s 'View Memory of' accessible from the context menu on a variable in the "Variables View" of Xcode's Debug Area.
So far, I've observed that stack memory addresses typically appear in the 0x16xxxxxxx range.
However, in some cases, the tool returns 0x0. Below is an example where this happens. When placing a breakpoint on the print(a) line, the 'View Memory of' tool returns 0x0 for the a constant. But if I change let a = 5 to var a = 5, I get a valid stack address instead.
Note: My project is built without optimizations.
My Question: Why does View Memory of return 0x0 in this case? What does it actually mean?
class ViewController: UIViewController {
override func loadView() {
super.loadView()
let a = 5
print(a)
}
}