• 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
Re: Blocking loops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Blocking loops


  • Subject: Re: Blocking loops
  • From: Drarok Ithaqua <email@hidden>
  • Date: Fri, 16 Jun 2006 20:47:16 +0100

Ah, excellent!
Just one problem I came across, all the autoreleased objects inside my loop built up and up and up and used over 1.2GB of RAM (looking at top in Terminal).
I added another autorelease pool inside the loop - I don't know how this is, performance wise, but it stopped my machine thrashing the virtual memory, at least.


Is this the correct way to use AR pools?

On 16 Jun 2006, at 5:16 pm, Shawn Erickson wrote:

On 6/16/06, cocoa <cocoa> wrote:

I think an NSThread is going to have to be my choice, could I ask a huge favour?
A rough example of how to implement an NSThread...

Sure no problem (the following is written in mail so not tested and just a real quick outline of what you can do)...

...
NSEnumerator* objectEnumerator = [myArray objectEnumerator];
[NSThread detachNewThreadSelector:@selector(processObjects:)
toTarget:self withObject:objectEnumerator];
...

- (void) processObjects:(NSEnumerator*)objectEnumerator
{
   NSAutorelease* pool = [[NSAutoreleasePool alloc] init];

   id object = [objectEnumerator nextObject];
   while (object != nil) {
       ... process object ...

       ... calculate percent done ...
       [progressBar
performSelectorOnMainThread:@selector(setObjectValue:)
withObject:[NSNumber numberWithFloat:percentDone] waitUntilDone:NO];

       [pool release];
       pool = [[NSAutoreleasePool alloc] init];
   }

   ... notify something when done if needed ... (many ways to do that)

   [pool release];
}

-Shawn

_______________________________________________ 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
  • Follow-Ups:
    • Re: Blocking loops
      • From: "Shawn Erickson" <email@hidden>
  • Prev by Date: Re: Text Capture in Cocoa
  • Next by Date: Re: Blocking loops
  • Previous by thread: Re: Blocking loops
  • Next by thread: Re: Blocking loops
  • Index(es):
    • Date
    • Thread