memshare_gc: Function to remove all handles (ownership and viewership) for...

View source: R/memshare_gc.R

memshare_gcR Documentation

Function to remove all handles (ownership and viewership) for a namespace in a worker context.

Description

Given a namespace identifier (identifies the shared memory space to register to), this function removes all handles to shared memory held by the master and a worker context.

Usage

  memshare_gc(namespace, cluster)

Arguments

namespace

string of the identifier of the shared memory context.

cluster

A worker context (parallel cluster) that holds views or pages in the same memory context as the master. NULL by default; then only the master session gets its handles removed.

Value

No return value, called deallocation of memory pages and views in a joint memory context.

Author(s)

Julian Maerte

See Also

releaseVariables, releaseViews

Examples

  cluster = parallel::makeCluster(1)
  
  mat = matrix(0,5,5)
  registerVariables("ns", list(mat=mat))
  
  parallel::clusterEvalQ(cluster, {
    view = memshare::retrieveViews("ns", c("mat"))
  })
  ## Not run: 
  # At this point each worker holds a view of mat
  
## End(Not run)
  memshare_gc("ns", cluster)
  ## Not run: 
  # Every workers viewership handle gets destroyed, master sessions page handle
  # gets destroyed.
  # As no handles are left open, the memory is free'd.
  
## End(Not run)
  parallel::stopCluster(cluster)

memshare documentation built on Dec. 5, 2025, 9:07 a.m.