Search code examples
cxcodemacoslldb

A way to view memory allocation in Xcode / lldb


I have a simple program and set a breakpoint to see how to monitor memory allocation within a debugging interface (instead of, for example, with valgrind):

enter image description here

The above program should allocate a lot of memory. It seems like the "Memory" icon on the left is unrelated to dynamic memory allocation (perhaps it's related to the amount of memory Xcode itself is using). Is there a command to see how much memory has been allocated within lldb, for example, similar to (gdb) call malloc_stats()? I know there is the Instruments application (which I've used), but I'm more interested in being able to step through the total memory usage while debugging it. Or, is there some GUI command/panel that will show this?


Solution

  • The memory gauge does reflect the memory your program allocates. If you do what Jason suggests, you will see that rise as you allocate more memory.

    There are a couple of commands: "memory region" and "malloc_info", that will tell you the allocation history or state of memory containing a particular address. But lldb doesn't have a general "show me all allocated memory regions" command, like malloc_stats.

    You can also use the Xcode "Debug Memory Graph" button to view the memory allocations - including all the Malloc blocks - in your program.