LOOP a QUEUE to Delete Records - Fastest is Reverse RECORDS to 1 BY -1

This conversation took place on Skype and I wanted to preserve the results @jslarve posted.

If your QUEUE contains an ANY or &STRING reference then doing a simple FREE(Q) will leak memory. You must Loop the records and Dispose(&String) or set ANY &= NULL. It’s not required to DELETE() each Queue record (see ABC code like Resizer or FieldPairsClass), but it is often done. Sometimes you are deleting a subset of records so must Delete(Q).

The point is if you have to delete QUEUE records LOOP in reverse is far faster. My understanding is Queues where changed to a Dynamic Array so cutting off the end seems like it would be faster.

This code so fast is takes almost no time

LOOP Ndx = RECORDS(Q) TO 1 BY -1
  GET(Q,Ndx)
  DELETE(Q)
END

This code is far slower.

LOOP
  GET(Q,1)
  IF ErrorCode() THEN BREAK END
  DELETE(Q)
END
4 Likes

Thanks for doing that, Carl

In truth the conversation was originally here.
I just posted @jslarve findings on skype
see —v
Data types 2 with Bruce- QUEUE with ANY - ClarionHub