+static void
+try_free_delayed_free_items (guint32 limit)
+{
+ GArray *hazardous = NULL;
+ DelayedFreeItem item;
+ guint32 freed = 0;
+
+ // Free all the items we can and re-add the ones we can't to the queue.
+ while (mono_lock_free_array_queue_pop (&delayed_free_queue, &item)) {
+ if (is_pointer_hazardous (item.p)) {
+ if (!hazardous)
+ hazardous = g_array_sized_new (FALSE, FALSE, sizeof (DelayedFreeItem), delayed_free_queue.num_used_entries);
+
+ g_array_append_val (hazardous, item);
+ continue;
+ }
+
+ item.free_func (item.p);
+ freed++;
+
+ if (limit && freed == limit)
+ break;
+ }
+
+ if (hazardous) {
+ for (gint i = 0; i < hazardous->len; i++)
+ mono_lock_free_array_queue_push (&delayed_free_queue, &g_array_index (hazardous, DelayedFreeItem, i));
+
+ g_array_free (hazardous, TRUE);
+ }
+}
+