Function concurrent::try_gc [] [src]

pub fn try_gc() -> Result<(), ()>

Attempt to collect garbage.

This function does two things:

  1. Export garbage from current thread to the global queue.
  2. Collect all the garbage and run destructors on the unused items.

If another thread is currently doing 2., it will be skipped. This makes it different from conc::gc(), which will block.

If 2. fails (that is, another thread is garbage collecting), Err(()) is returned. Otherwise Ok(()) is returned.

Use case

Note that it is not necessary to call this manually, it will do so automatically after some time has passed.

However, it can be nice if you have just trashed a very memory-hungry item in the current thread, and want to attempt to GC it.

Other threads

This cannot collect un-propagated garbage accumulated locally in other threads. This will only attempt to collect the accumulated local and global (propagated) garbage.

Panic

If a destructor panics during the garbage collection, theis function will panic aswell.