Re: NSOperationQueue question
Re: NSOperationQueue question
- Subject: Re: NSOperationQueue question
- From: Tim Murison <email@hidden>
- Date: Fri, 07 Aug 2009 19:07:06 -0400
- Thread-topic: NSOperationQueue question
On 07/08/09 5:30 PM, "Quincey Morris" <email@hidden> wrote:
> On Aug 7, 2009, at 14:06, Tim Murison wrote:
>
>> The improved code will execute about 1000 operations as quickly as
>> possible,
>> then it will sleep for 1 second. Before sleeping, it will print the
>> operation queue length, proving that the queue doesn't grow for ever
>> (it is
>> always < 5000 on my machine). Finally, the long sleep means that CPU
>> use is
>> low giving GC plenty of time to do its work (even without the [pool
>> drain]
>> hint.) Each iteration of the loop will attempt to collect the garbage.
>
> That's not how I read it. The code will flood the operation queue
> until 1000 operations have incremented the counter (which is almost,
> but not quite, the same thing as saying that 1000 operations have
> finished executing).
>
> At that point, there may be many thousands of pending operations still
> to be executed. That's not a quiescent state. You need to stop queuing
> operations, then wait for the queue to empty and wait for all
> operation threads to cease existing and wait for the garbage collector
> to run as many times as it wants until it has nothing left to collect,
> and *then* you have a quiescent state.
I think my previous sample was good enough, but this should be perfect (only
the important part this time) :)
if (tmp - last > 1000) {
while ([[queue operations] count]) {
usleep(100);
}
last = tmp;
printf("Queue length:%d\n", [[queue operations] count]);
usleep(1000 * 10000);
[[NSGarbageCollector defaultCollector] collectExhaustively];
}
I enqueue operations until ~1000 have executed, then wait for the queue to
be empty. Then sleep for 10 seconds and force a collection. Once the queue
is empty there should be a maximum of 4 outstanding operations (the
concurrency count). 10 seconds should be plenty of time to finish servicing
them.
Needless to say, I still get the memory increase. I don't with
retain/release code. This isn't a hypothetical question, I do have a real
program with real operations that exhibits this behaviour, and unfortunately
it is not written for retain/release.
-Tim
***********************************************************************
This e-mail and its attachments are confidential, legally privileged, may be subject to copyright and sent solely for the attention of the addressee(s).
Any unauthorized use or disclosure is prohibited. Statements and opinions expressed in this e-mail may not represent those of Radialpoint.
Le contenu de ce courriel est confidentiel, privilégié et peut être soumis à des droits d'auteur. Il est envoyé à l'intention exclusive de son ou de ses
destinataires. Il est interdit de l'utiliser ou de le divulguer sans autorisation. Les opinions exprimées dans le présent courriel peuvent diverger de celles de Radialpoint.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden