Memory Management
Memory Management
- Subject: Memory Management
- From: Jordan Evans <email@hidden>
- Date: Fri, 30 Dec 2005 15:09:27 -0800 (PST)
I'm having some difficulty with the memory management
with Cocoa. The best way I can explain the situation
is by giving an analogy, because my real example would
be harder to explain.
I have a Car Class. Inside this Car Class, there is an
instance of an engine object from an Engine Class. The
Engine Class is composed of objects, which make up the
engine. From time to time, the car object is taken
into the garage and a few parts for the engine need to
be replaced, but not the whole engine. The way these
parts are maintained in Objective-C lingo is that old
parts are deallocated and replacement parts are
allocated.
I know during the program execution that maintenance
will occur several times. I have no idea which parts
will be replaced each time maintenance is needed, so
memory allocation and deallocation has to be flexible.
I can't just remove a certain list of parts. And it
makes no sense to replace the engine every time. I
only want to replace the parts that need to be
replaced, which means I need to deallocate them and
create new object versions of them for my Engine
instance.
The engine instance is in an NSAutoreleasePool
instance. The only way I can replace bad parts is to
release the pool to which all engine parts belong to.
If I retain the parts that don't need to be replaced
and then release the pool, it would work. But I would
then have a new problem. Now the other parts are just
floating around and I can't replace them by
deallocating them, unless I create a new pool and add
them via NSAutoreleases -addObject: method, then
release that pool. But I'm not sure if this is the
best way to handle it.
I would just send a free message to replacement parts
and simply allocated new ones, but Cocoa forces some
of my objects into the pool that is currently on the
top of the stack, making a situation more complex than
just simple freeing them with a message.
I need some input on the best way to deal with this.
Its there anyway to stay away from pools completely or
how do I use pools in this situation?
__________________________________________
Yahoo! DSL Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com
_______________________________________________
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