adopt<T extends IUnknown> method

T adopt<T extends IUnknown>(
  1. T object
)

Adopts an existing COM object into this Arena.

This method transfers ownership of an already-created COM interface to the arena. The arena will call release exactly once when it is disposed.

Example:

using((arena) {
  // Create a COM object whose lifetime is owned by the arena.
  final dialog = arena.com<IFileOpenDialog>(FileOpenDialog);

  // Query a secondary interface and explicitly adopt it into the same
  // arena.
  final dialog2 = arena.adopt(dialog.queryInterface<IFileDialog2>());

  // No explicit release calls are required.
  // The arena will call release on both `dialog` and `dialog2`
  // when this block exits.
});

Implementation

T adopt<T extends IUnknown>(T object) =>
    this.using(object, (o) => o.release());