clear_buffer_memory

clear_buffer_memory#

class brainstate.util.clear_buffer_memory(platform=None, array=True, compilation=False)#

Clear on-device memory buffers and optionally compilation cache.

This function is useful when running models in loops to prevent memory leaks by clearing cached arrays and freeing device memory.

Warning

This operation may invalidate existing array references. Regenerate data after calling this function.

Parameters:
  • platform (str | None) – The specific device platform to clear. If None, clears the default platform.

  • array (bool) – Whether to clear array buffers.

  • compilation (bool) – Whether to clear the compilation cache.

Return type:

None

Examples

>>> clear_buffer_memory()  # Clear array buffers
>>> clear_buffer_memory(compilation=True)  # Also clear compilation cache