IOS Objec-C error to free object pointer was not highlighted

I get the following error in xcode.

error for object 0x4e18d00: pointer freed; ** set breakpoint in malloc_error_break for debugging

I set NSZombieEnabled to target so that I can view the call.

- [___ NSArrayI release]

It looks like I released some array somewhere else in my code, and then the auto-release pool tries to free it even when it is already disabled.

How to find out where? Any idea?

FYI, I create all my arrays using the arrayWithCapacity method or something similar, never use the alloc or init methods. I don't see anywhere where I release the same arrays. (maybe I'm blind !!)

In addition, the control flow is as follows: I press the UIButton button, start the function attached to onclick. This will go to various logical levels and then return NSArray back. Then I can iterate over this array into the "onClick button" function and print the contents. When this "onClick button" function completes, I get the above error in the "main" method.

One more note: in one function, I create an NSMutableArray, but want to return an NSArray , so I use [[mutableArray copy] autorelease] . This is normal, right?

We will be very grateful for any advice, as I often have great difficulty trying to track the cause of errors.

Thanks in advance.

+4
source share
2 answers

I realized what was wrong.

In the book class, I had chapters declared as NSAray, and in the default constructor I said

 chapters = [NSArray array]; 

I took it from the constructor, and everything is fine. Thanks for helping the guys.

PS If I forget, can anyone mark this as an accepted answer? Greetings;)

+1
source

When your application crashes, you can see on which line your application crashed, and you can also see a sequence of functions called before the crash. I think this line crashes [[mutableArray copy] autorelease]. because you do not save it. copy returns an auto-implemented object. In the documentation you can see what the function returns. Object-c usually returns an object with auto-implementation.

-1
source

All Articles