For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/lynx-native-api/lynx-extension-module/release.md.
Lynx
  • English
  • Release

    The Release method provides manual control over the reference count of the underlying lynx_extension_module_t C-API object. This is an advanced feature that should be used with caution.

    In most scenarios, the Lynx framework manages the lifecycle and memory of the extension module automatically. You typically do not need to call these methods.

    Release()

    Decrements the reference count of the C-API object. When the reference count drops to zero, the object will be destroyed, and its memory will be freed.

    Method Signature

    void Release();

    Usage

    These methods are useful in specific interoperability scenarios where you need to pass ownership of the module to another system or manage its lifecycle outside the standard Lynx flow. For example, if you store a raw pointer to the module in a separate, long-lived object, you should Retain it to ensure it remains valid and Release it when you are done.

    Example

    #include "lynx_extension_module.h"
    
    class SomeOtherSystem {
    public:
        SomeOtherSystem() = default;
        SomeOtherSystem(const SomeOtherSystem&) = delete;
        SomeOtherSystem& operator=(const SomeOtherSystem&) = delete;
    
        void TakeOwnership(lynx::pub::LynxExtensionModule* module) {
            if (module == _module) {
                return;
            }
            if (module) {
                module->Retain(); // Retain the incoming module first
            }
            if (_module) {
                _module->Release();
            }
            _module = module;
        }
    
        ~SomeOtherSystem() {
            if (_module) {
                _module->Release();
            }
        }
    private:
        lynx::pub::LynxExtensionModule* _module = nullptr;
    };
    
    // ...
    // Somewhere in your code:
    // Assume my_module is a valid extension module already bound with SetCModule.
    // some_other_system.TakeOwnership(my_module);
    // ...

    Warning

    Incorrectly managing the reference count can lead to memory leaks (if Release is not called enough) or crashes due to use-after-free errors (if Release is called too many times). Use these methods only if you have a clear understanding of the object ownership requirements.

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.