Memory management in a thread
Memory management in a thread
- Subject: Memory management in a thread
- From: Randall Meadows <email@hidden>
- Date: Fri, 12 Mar 2004 14:39:30 -0500
In my program I kick off a thread to do some intense processing of a
bunch of data. At the top of the thread method, I create an
NSAutoreleasePool, which I release at the end of that method (when
the thread is effectively done). In between these two events, I
create a *bunch* of autoreleased objects, mostly from methods like
[NSArray arrayWithObjects], [NSString stringWithFormat], etc., in a
nested looping construct which make a bunch of function calls.
Something like this pseudo-code:
doThreadProcess {
pool = [[NSAutoreleasePool alloc] init]
projects = ProjectList
for each project in projects
files = ProjectFiles
for each file in files
revs = FileRevisions
for each rev in revs
check for user abort
ProcessRevision
end
end
end
[pool release]
}
NSArray * ProjectFiles {
data = ReadProjectData
create array
for each entry in data
string = [NSString stringFromCString:]
add string to array
end
return array
}
etc.
They get [auto]released when the pool is released, right? If so,
that means I'm going to have a *LOT* of unused objects taking up
memory in the midst of my loop.
Or am I confused? I'm guessing I cannot release on an
already-autoreleased object, right? What to do to clean up my loop?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.