Re: Pointer was being free was not allocated
Re: Pointer was being free was not allocated
- Subject: Re: Pointer was being free was not allocated
- From: Uli Kusterer <email@hidden>
- Date: Wed, 13 Feb 2013 14:32:28 +0100
Sounds like a classic memory management error. Either you are using a pointer to an object after you've released it, or you are keeping an autoreleased pointer beyond the lifetime of the current autorelease pool without retaining it, or a pointer to an object inside an NSArray or NSDictionary after you've released the array. Often people also do this by e.g. forgetting to retain an object when they place it into an instance variable of another object. Or handing the -bytes pointer of an NSData object to some C code that then tries to call DisposePtr() or free() on it (in which case you should copy the NSData into a newly malloc()ed pointer.
If it's not that, then you're likely declaring a local variable or malloc()ing a struct somewhere and forgetting to initialize it to 0 (or in some other way remembering that you haven't allocated memory of a pointer in it). Only objects are initialized to 0 when you allocate them.
A good exercise is to set all pointer variables to nil (or NULL, for non-objects) right when declaring them, and setting them back to that again right after you call release on them.
There's also a final, much less likely possibility: That there is actually a bug in some MacOS API you are using. But that is rather unlikely. That you have the bug on 17.7+ but not on 10.6 could mean the bug is new with 10.6. OTOH it could also mean that 10.6 had a bug that was fixed in 10.7, or that you wrote code assuming a bug in 10.6 was how it's supposed to be even though the documentation (and fixed behavior in 10.7 and later) corrected it. Much more likely, however, the bug is yours and already there in 10.6, and Apple just added a few more sanity checks in 10.7 and hence it's the first time you get reliably warned about your mistake.
(Of course, if you're using ARC instead of manual retain/release, the above can also happen, but are much harder to track down because you're only indirectly causing the compiler to insert the "wrong" retain/release calls, they're not explicit in your code)
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
On Feb 13, 2013, at 12:50 PM, anni saini <email@hidden> wrote:
> Can anybody know how to resolve the issue of "Pointer was being free was not allocated" I was facing this issue with my project on 10.7 and 10.8 however the code works perfectly fine on 10.6. Any idea what is causing this?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden