NSZombieEnabled does not work

前端 未结 8 1804
谎友^
谎友^ 2020-12-15 07:59

When I set NSZombieEnabled = Yes nothing is written to the console. How can I fix this? Or can you advise me any other tools for an EXC_BAD_ACCESS?

8条回答
  •  没有蜡笔的小新
    2020-12-15 08:00

    Also make sure you initialize all pointers to nil before using them!

    If you use a pointer without initializing it to nil or any other object, you are propably going to end up accessing memory which isn't yours.

    For example the following code will also give an EXC_BAD_ACCESS which is not traceable using the NSZombieEnabled flag caused by the last line.

    RecordingLocation* closest;
    
    //find the closest recording location
    for (...)
    {
        //try to find the closest object...
        //suppose we don't find anything so closest is never set.
    }
    
    if (closest!=nil)
        NSLog(@"Closest: %f,%f",closest.x,closest.y);
    

提交回复
热议问题