retainLib static method

void retainLib(
  1. String libName
)

Takes a reference to an already-loaded libName, balancing the releaseLib a generated bridge performs in dispose().

Native takes a lib reference per instance via loadLib; on web the module loads once in ensure<Class>Ready(), so instances must retain separately or the first dispose() evicts the module for everyone.

No-op when the module is not loaded — the bridge constructor reports it.

Implementation

static void retainLib(String libName) {
  if (!_moduleCache.containsKey(libName)) return;
  _libRefCount[libName] = (_libRefCount[libName] ?? 0) + 1;
}