Skip to main content

GarbageCollector

Index

Constructors

constructor

Properties

publicoptions

Methods

addCollectableResource

  • addCollectableResource(type: string, resource: any): void
  • Add a resource to be tracked for collection


    Parameters

    • type: string
    • resource: any

    Returns void

publiccollectStaleResources

  • collectStaleResources(deadline?: IdleDeadline): void
  • Runs the collection loop to cleanup any stale resources given the registered collect handlers


    Parameters

    • optionaldeadline: IdleDeadline

    Returns void

publicforceCollectAll

  • forceCollectAll(): void
  • Force collect all resources, useful for shutting down a game or if you know that you will not use anything you've allocated before now


    Returns void

registerCollector

  • registerCollector(type: string, timeoutInterval: number, collect: (resource: any) => boolean): void
  • Parameters

    • type: string

      Resource type

    • timeoutInterval: number

      If resource type exceeds interval in milliseconds collect() is called

    • collect: (resource: any) => boolean

      Collection implementation, returns true if collected

    Returns void

start

  • start(): void
  • Starts the garbage collection loop


    Returns void

stop

  • stop(): void
  • Stops the garbage collection loop


    Returns void

touch

  • touch(resource: any): void
  • Update the resource last used timestamp preventing collection


    Parameters

    • resource: any

    Returns void