Skip to content
DebugService

Service / DebugService

DebugService Class

Instance

Debug test run service

Table of contents

Methods

getHeapStatistics(): HeapStatistics other
Retrieve the memory usage of all TS scripts in the current project

Methods

getHeapStatistics

Static getHeapStatistics(): HeapStatistics other

Retrieve the memory usage of all TS scripts in the current project

Returns

HeapStatisticsHeapStatistics Memory data

Usage example: create a script named DebugExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the client and server log will output the usage of ts memory every 2 seconds

ts
@Component
export default class DebugExample extends Script {

    protected onStart(): void {
        TimeUtil.setInterval(() => {
            const heapStatistics = DebugService.getHeapStatistics();
            Console. log ("-------- Current ts memory usage --------");
            Console.log ("total heap size", heapStatistics.totalHeapSize);
            Console.log ("total executable heap size", heapStatistics.totalHeapSizeExecutable);
            Console.log ("Used heap size", heapStatistics.usedHeapSize);
            Console. log ("dynamically allocated memory", heapStatistics.memoryAllocated ? heapStatistics.memoryAllocated : 0);
            Console.log ("Dynamic memory Allocation Peak", heapStatistics.peakMemoryAllocated ? heapStatistics.peakMemoryAllocated : 0);
        }, 2);
    }
}
@Component
export default class DebugExample extends Script {

    protected onStart(): void {
        TimeUtil.setInterval(() => {
            const heapStatistics = DebugService.getHeapStatistics();
            Console. log ("-------- Current ts memory usage --------");
            Console.log ("total heap size", heapStatistics.totalHeapSize);
            Console.log ("total executable heap size", heapStatistics.totalHeapSizeExecutable);
            Console.log ("Used heap size", heapStatistics.usedHeapSize);
            Console. log ("dynamically allocated memory", heapStatistics.memoryAllocated ? heapStatistics.memoryAllocated : 0);
            Console.log ("Dynamic memory Allocation Peak", heapStatistics.peakMemoryAllocated ? heapStatistics.peakMemoryAllocated : 0);
        }, 2);
    }
}