I am trying to resolve a "message sent to deallocated instance " error in iOS.
-
Use instruments, it gives you that info. – Richard J. Ross III Mar 16 '12 at 14:29
-
2@Richard, Using the Zombie instrument will help you debug that, but sometimes it is nice to know the history of the malloc while sitting in gdb. – Sonny Saluja Apr 23 '12 at 18:36
-
That would be fine if Instruments didn't lock up the machine – Bradley Thomas Dec 09 '16 at 01:35
3 Answers
See the LLDB-GDB command map (http://lldb.llvm.org/lldb-gdb.html) - you have to import a script, and the command is named malloc_info now. Obviously, malloc stack logging still needs to be turned on in the scheme options.
(lldb) script import lldb.macosx.heap
(lldb) malloc_info --stack-history 0x10010d680
Unfortunately, it doesn't show dealloc's - didn't GDBs malloc-history show that as well?

- 1,482
- 11
- 8
-
when I looked at the linked page, it showed those commands as "available on Mac OS X only" – Walt Sellers Oct 09 '13 at 05:44
-
5For me, the first line had to be 'command script import lldb.macosx.heap', otherwise the console would report 'error: 'malloc_info' is not a valid command.' (Mac OS) – Shaun Budhram Oct 31 '14 at 05:43
-
`(lldb) script import lldb.macosx.heap` *>>> "crashlog" and "save_crashlog" command installed, use the "--help" option for detailed help "malloc_info", "ptr_refs", "cstr_refs", "find_variable", and "objc_refs" commands have been installed, use the "--help" options on these commands for detailed help.* – Zeus May 20 '16 at 05:56
Use instruments, you'll get the exact line -
(In XCode) Run it through "Product" -> "Profile".
This will start Instruments, there you should choose "Zombies" and reproduce the bug event.
You'l get a pop-up once a zombie is called, press the chevron to see the exact line.
Problem is usually a bad __bridge
(optional bridges __brige_retained
/ __bridge_transfer
/ __bridge
)

- 3,175
- 3
- 30
- 36

- 2,418
- 1
- 22
- 40
-
-
@lwdthe1 You can see in Xcode output the deallocated Class that the message was sent to - it would give you a hint regarding the deallocated instance. – Avishay Cohen Jan 26 '17 at 11:06
You used to be able to use the malloc_history command-line tool from a shell and give it the process ID and address of interest. It appears this command is no longer installed by the latest Xcode's command line tools. :-(

- 201
- 2
- 3