GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Classes | Static Public Member Functions | List of all members
gd::MemoryTrackedRegistry Class Reference

A static registry tracking the lifetime of C++ objects exposed to JavaScript via Emscripten/WebIDL bindings. More...

#include <MemoryTrackedRegistry.h>

Static Public Member Functions

static void add (const void *ptr, const char *className)
 
static void remove (const void *ptr, const char *className)
 
static bool isDead (const void *ptr, const char *className)
 
static void add (long ptr, const gd::String &className)
 
static void remove (long ptr, const gd::String &className)
 
static bool isDead (long ptr, const gd::String &className)
 
static long getDeadCount ()
 
static void pruneDead (long maxSize)
 
static long getAliveCount ()
 
static long getAliveCountForClass (const gd::String &className)
 
static long getDeadCountForClass (const gd::String &className)
 
static void setCurrentCallContextId (long id)
 
static long getDeadContextId (long ptr, const gd::String &className)
 
static double getDeadContextTimeMs (long ptr, const gd::String &className)
 

Detailed Description

A static registry tracking the lifetime of C++ objects exposed to JavaScript via Emscripten/WebIDL bindings.

Uses two maps keyed by className, each mapping to a set of pointers:

Additionally stores a bounded ring buffer of destruction contexts per class, capturing which JS call triggered each destruction and when it happened.

This allows JavaScript wrappers to detect use-after-free by calling isDead(), and enables per-class statistics for debugging.

Member Function Documentation

◆ getDeadContextId()

static long gd::MemoryTrackedRegistry::getDeadContextId ( long  ptr,
const gd::String className 
)
inlinestatic

Returns the call-context ID that was active when the object was destroyed, or -1 if the context has been evicted from the ring buffer.

◆ getDeadContextTimeMs()

static double gd::MemoryTrackedRegistry::getDeadContextTimeMs ( long  ptr,
const gd::String className 
)
inlinestatic

Returns the wall-clock timestamp (ms since Unix epoch) when the object was destroyed, or 0 if the context is not available.

◆ setCurrentCallContextId()

static void gd::MemoryTrackedRegistry::setCurrentCallContextId ( long  id)
inlinestatic

Set by JS before each wrapped method call (integer ID, ~50-100ns).


The documentation for this class was generated from the following file: