Re: Memory Management: Revamped Engine Example
Re: Memory Management: Revamped Engine Example
- Subject: Re: Memory Management: Revamped Engine Example
- From: Scott Ribe <email@hidden>
- Date: Sun, 01 Jan 2006 19:15:38 -0700
- Thread-topic: Memory Management: Revamped Engine Example
> My goal here is to have maintenance cause the
> dealloc'ing of bad parts. I'm trying to do that as
> soon as they are replaced. Why? Suppose I my engine
> grows in size and has millions of parts. If the parts
> get put in an autorelease pool that doesn't remove
> them in time, I'll have a bunch of parts that aren't
> in use taking up memory. So, when they are replaced in
> -maintenance, I'm trying to get them dealloc'd
> immediately. I just want to make sure that is done.
Well, in that case I think you're on the right track now. At init, put the
good parts in the array, then release them so that the array is holding the
only references, and don't use autorelease. In maintenance, when they're
removed from the array they'll be released, and since they haven't been
retained elsewhere they'll be dealloc'd. (Assuming they haven't been
retained elsewhere, and it sounds like in this case that would be a bug
elsewhere in your code if they were.)
An autorelease pool is intended to help with the case where you may be
creating and releasing millions of objects in a loop, but they won't help
you here because you can't effectively use one outside of the:
1) create pool
2) run loop
3) release pool
kind of scenario. There was a discussion on this recently, but that's
basically what the warning in the docs mean about creating and releasing in
the same context--because of all the autoreleasing that happens in system
calls it's hard to create a pool in one method and release in another
without creating problems.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 665-7007 voice
_______________________________________________
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