• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Memory management in a thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Memory management in a thread
      • From: Allan Odgaard <email@hidden>
    • RE: Memory management in a thread
      • From: "Jonathan E. Jackel" <email@hidden>
  • Prev by Date: Re: Odd binding issue
  • Next by Date: RE: Memory management in a thread
  • Previous by thread: Re: Remote server info
  • Next by thread: RE: Memory management in a thread
  • Index(es):
    • Date
    • Thread