The AdaptObjectLifetime class stores a list of AdaptObjects existing within that lifetime.

When you no longer need an object, call lifetime.Finalize(), which in turn calls AdaptObject.Destroy() for every stored object.

Note: The value implementing this interface must have a Destroy method.

The need for this mechanism is dictated by the Wasm deployment of ADAPT, in which no automated garbage-collection of JS-referenced objects is currently possible. Expect this mechanism to become deprecated when the Wasm community wakes up and fixes this insanity.

Table of contents

Constructors

Methods

Constructors

constructor

• new AdaptObjectLifetime()

Defined in

common/dist/memory_management/adapt_object_lifetime.d.ts:97

Methods

Deposit

▸ Deposit(object): void

Attach an object to the given lifetime object.

Example

AdaptEnvironment.InitializeAsync().then(() => {
     const lifetime = new AdaptObjectLifetime();
     const value = new AdaptValue(undefined, 5);
     lifetime.Deposit(value);

     lifetime.Finalize();
})

Parameters

Name Type Description
object AdaptObject The object to be attached to the lifetime object

Returns

void

Defined in

common/dist/memory_management/adapt_object_lifetime.d.ts:115


Finalize

▸ Finalize(): void

Destroy all the objects managed by the lifetime.

Example

AdaptEnvironment.InitializeAsync().then(() => {
     const lifetime = new AdaptObjectLifetime();
     const value = new AdaptValue(lifetime, 5);
     const value1 = new AdaptValue(lifetime, 6);

     lifetime.Finalize(); // both value and value1 get destroyed by this call
})

Returns

void

Defined in

common/dist/memory_management/adapt_object_lifetime.d.ts:153


Withdraw

▸ Withdraw(object): boolean

Delete an object from the set of objects managed by the lifetime, so the object does not get deleted when the Finalized method is called.

Note: This method does not destroy the object.

Example

AdaptEnvironment.InitializeAsync().then(() => {
     const lifetime = new AdaptObjectLifetime();
     const value = new AdaptValue(lifetime, 5);
     lifetime.Withdraw(value);

     lifetime.Finalize(); // value is not destroyed
     value.Destroy();
})

Parameters

Name Type Description
object AdaptObject The object to delete from the lifetime

Returns

boolean

True if the object was deleted from the lifetime, otherwise false

Defined in

common/dist/memory_management/adapt_object_lifetime.d.ts:136