Re: Autoreleasepool problems
Re: Autoreleasepool problems
- Subject: Re: Autoreleasepool problems
- From: Jerry Krinock <email@hidden>
- Date: Wed, 19 Jul 2006 12:39:31 -0700
- Thread-topic: Autoreleasepool problems
on 06/07/19 12:16, Kay Roepke at email@hidden wrote:
>
> On 19. Jul 2006, at 20:28 Uhr, Kay Roepke wrote:
>
>> ObjectAlloc doesn't show me any overreleased objects at all.
>> Everything is balanced, save the extra entry in the pool.
I've never used ObjectAlloc, but what Shawn says is true. I made one of
these errors a couple weeks ago and it took me a half day to find it. So, I
wrote down this blow-by-blow description of what happens. Although it says
the same thing that Shawn said, maybe this will help engage your brain to
find this one:
1. Get a temporary, autoreleased object, A.
2. By mistake, -release object A.
3. Do alot of other stuff in different classes, executing many lines of
code, in different files.
4. Create an object B which you'll need later. Follow proper memory
management rules so that it has an apparent retainCount of 1.
5. Return all functions so that run loop cycles and releases the app's
autorelease pool.
6. Send a message to object B.
Result: App crashes.
Variation: If you send B an extra -retain before step 5, app does not crash.
Probable Explanation: When you released object A, its memory space became
available. The system re-used this space when allocating B. Then when the
autorelease pool was released, A was still in the autorelease pool, so a
release message was sent to the address of A, which was now the address of
B, so B got released and was deallocated and maybe overwritten by something
else. So the next time you tried to access B, it crashes.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden