Skip to content

⬅️ Back to Table of Contents

📄 useMemory

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 6
📐 Interfaces 3
📑 Type Aliases 1

📚 Table of Contents

🛠️ File Location:

📂 packages/core/useMemory/index.ts

📦 Imports

Name Source
ShallowRef vue
ConfigurableScheduler ../_configurable
Supportable ../types
useIntervalFn @vueuse/shared
shallowRef vue
useSupported ../useSupported

Functions

useMemory(options: UseMemoryOptions): UseMemoryReturn

Reactive Memory Info.

Parameters:

  • options any: No description

See: https://vueuse.org/useMemory

Tags: @__NO_SIDE_EFFECTS__

Raw JSDoc
/**
 * Reactive Memory Info.
 *
 * @see https://vueuse.org/useMemory
 * @param options
 *
 * @__NO_SIDE_EFFECTS__
 */

Calls:

  • shallowRef (from vue)
  • useSupported (from ../useSupported)
  • scheduler
Code
export function useMemory(options: UseMemoryOptions = {}): UseMemoryReturn {
  const memory = shallowRef<MemoryInfo>()
  const isSupported = useSupported(() => typeof performance !== 'undefined' && 'memory' in performance)

  if (isSupported.value) {
    const {
      scheduler = useIntervalFn,
    } = options

    scheduler(() => {
      memory.value = (performance as PerformanceMemory).memory
    })
  }

  return { isSupported, memory }
}

Interfaces

MemoryInfo

Interface Code
export interface MemoryInfo {
  /**
   * The maximum size of the heap, in bytes, that is available to the context.
   */
  readonly jsHeapSizeLimit: number
  /**
   *  The total allocated heap size, in bytes.
   */
  readonly totalJSHeapSize: number
  /**
   * The currently active segment of JS heap, in bytes.
   */
  readonly usedJSHeapSize: number

  [Symbol.toStringTag]: 'MemoryInfo'
}

Properties

Name Type Optional Description
jsHeapSizeLimit number not shown
totalJSHeapSize number not shown
usedJSHeapSize number not shown
[Symbol.toStringTag] 'MemoryInfo' not shown

UseMemoryOptions

Interface Code
export interface UseMemoryOptions extends ConfigurableScheduler {
}

UseMemoryReturn

Interface Code
export interface UseMemoryReturn extends Supportable {
  memory: ShallowRef<MemoryInfo | undefined>
}

Properties

Name Type Optional Description
memory ShallowRef<MemoryInfo \| undefined> not shown

Type Aliases

PerformanceMemory

type PerformanceMemory = Performance & {
  memory: MemoryInfo
};

Generated by Syntax Scribe