Larvitar Documentation
Home
Guide
API
GitHub
Home
Guide
API
GitHub
  • API

    • Initializing
    • Parsing
    • Loading
    • Rendering
    • Interacting
    • Testing
    • Modules

      • Logger
      • Store
      • Managers

        • Image Manager
        • GSPS Manager
        • File Manager
      • Parsers

        • PDF Parser
        • NRRD Parser
        • ECG Parser
      • Loaders
        • DICOM Loader
        • MultiFrame Loader
        • SingleFrame Loader
        • DSA Image Loader
        • File Loader
        • Nrrd Loader
      • Interaction Tools

        • Initialize and manage Tools
        • Default and Custom Tools
        • Segmentation Tools
        • DvTools
      • Utilities

        • DICOM Anonymization
        • DICOM Customization
        • Tags
        • Utils
        • Memory
      • Post Processing

        • DSA
      • Visualizations

        • Layers
        • ECG
        • Color Maps
        • Greyscale Presentation States
      • Testing
Larvitar

Memory Monitoring Module

Overview

The Memory Monitoring module provides utility functions for tracking and managing memory usage within an application. It ensures efficient memory allocation and prevents excessive usage by monitoring JavaScript heap size and clearing unnecessary data when needed.

API Reference

checkAndClearMemory

Description

Checks memory allocation and clears non-rendered series from memory if necessary.

Syntax

checkAndClearMemory(bytes: number, renderedSeriesIds: string[]): void

Parameters

ParameterTypeDescription
bytesNumberThe number of bytes to allocate.
renderedSeriesIdsArray of StringsList of rendered series IDs.

Example

checkAndClearMemory(50000000, ["series1", "series2"]);

checkMemoryAllocation

Description

Checks memory allocation and returns false if the JavaScript heap size limit is reached.

Syntax

checkMemoryAllocation(bytes: number): boolean

Parameters

ParameterTypeDescription
bytesNumberThe number of bytes to allocate.

Returns

boolean - true if there is enough memory, false otherwise.

Example

const isEnough = checkMemoryAllocation(50000000);

getUsedMemory

Description

Retrieves the amount of memory currently used in the JavaScript heap.

Syntax

getUsedMemory(): number

Returns

number - Used JS heap size in bytes, or NaN if unsupported.

Example

const usedMemory = getUsedMemory();

getAvailableMemory

Description

Returns the available JavaScript heap size.

Syntax

getAvailableMemory(): number

Returns

number - Available JS heap size in bytes, or NaN if unsupported.

Example

const availableMemory = getAvailableMemory();

setAvailableMemory

Description

Sets a custom maximum available memory limit.

Syntax

setAvailableMemory(value: number): void

Parameters

ParameterTypeDescription
valueNumberMemory limit in gigabytes.

Example

setAvailableMemory(4);

Internal Utility Functions

checkMemorySupport

Description

Checks if performance.memory is supported in the browser.

Syntax

checkMemorySupport(): boolean

Returns

boolean - true if supported, false otherwise.

Example

const isSupported = checkMemorySupport();

getMB

Description

Converts bytes to megabytes.

Syntax

getMB(bytes: number): number

Parameters

ParameterTypeDescription
bytesNumberMemory in bytes.

Example

const memoryInMB = getMB(1048576);

Constants

backingMemory

  • A constant defining 100 MB (100 * 1048576) reserved memory.

customMemoryLimit

  • A variable that stores the user-defined memory limit.

Dependencies

  • getImageManager(), removeDataFromImageManager(), clearImageCache(), and store from external modules.

Warnings & Considerations

  • This module ensures efficient memory management, preventing excessive memory usage.
  • Works only in browsers that support performance.memory (Chrome-based browsers).


D/Vision Lab
Last Updated:
Contributors: Laura Borghesi, Simone "Lateralus" Manini
Prev
Utils