Skip to main content

Clean

Cleans all resources managed by the Vault and prepares it for garbage collection.

const vault = new Vault()

const part = new Instance("Part")
part.Parent = workspace
vault.Add(part)

const connection = part.Touched.Connect(() => {
print("Touched")
})
vault.Add(connection)

vault.Clean()

Behavior

The Clean method performs a comprehensive cleanup of the Vault and its resources:

  1. Prevents double-cleaning: If the vault was already cleaned, returns immediately
  2. Hierarchical cleanup: Recursively cleans all child vaults first
  3. Resource cleanup: Executes cleanup logic for every tracked resource
  4. State reset: Clears all internal tracking structures
  5. Parent detachment: Removes itself from parent vault's children collection