Poco::JS::Core

class WeakPersistentWrapperRegistry

Library: JS/Core
Package: Wrappers
Header: Poco/JS/Core/Wrapper.h

Description

This class maintains references to all active WeakPersistentWrapper instances.

The V8 engine won't properly garbage-collect any remaining objects when a script's context is disposed. This is not an issue for pure JavaScript objects, as they reside in the JavaScript heap, which will eventually be freed when the Isolate is disposed. This is, however, an issue for wrapped, heap-allocated native objects. If they're not garbage collected, the destructors of the wrapped C++ objects will never be called.

Therefore, we register each WeakPersistentWrapper wrapper in a Isolate-specific registry. If at the time we dispose of the Isolate any wrappers for that Isolate remain in the registry, we can safely delete them, ensuring that all wrapped C++ objects are properly deleted.

Member Summary

Member Functions: cleanup, cleanupIsolate, forIsolate, registerWrapper, unregisterWrapper

Types Aliases

Ptr

using Ptr = Poco::SharedPtr < WeakPersistentWrapperRegistry >;

Constructors

WeakPersistentWrapperRegistry

WeakPersistentWrapperRegistry();

Destructor

~WeakPersistentWrapperRegistry

~WeakPersistentWrapperRegistry();

Destroys the WeakPersistentWrapperRegistry and deletes any WeakPersistentWrapper instances still registered.

Member Functions

cleanupIsolate static

static void cleanupIsolate(
    v8::Isolate * pIsolate
);

Destroys the WeakPersistentWrapperRegistry instance for the given Isolate, if one exists.

forIsolate static

static WeakPersistentWrapperRegistry & forIsolate(
    v8::Isolate * pIsolate
);

Returns the WeakPersistentWrapperRegistry for the given Isolate. If no WeakPersistentWrapperRegistry for that Isolate exists, a new one is created, otherwise the existing instance is returned.

registerWrapper

void registerWrapper(
    WeakPersistentWrapperBase * pWrapper
);

Registers a WeakPersistentWrapper instance.

unregisterWrapper

void unregisterWrapper(
    WeakPersistentWrapperBase * pWrapper
);

Unregisters a WeakPersistentWrapper instance.

cleanup protected

void cleanup();

Deletes all registered wrappers.

Securely control IoT edge devices from anywhere   Connect a Device