Skip to content

Watcher Callbacks Should Use JSManagedValue to Avoid GC Issues #16

@alkene5

Description

@alkene5

Currently, various watchers in the HSApplicationModule (e.g., _addWatcher) store their JavaScript callbacks directly as JSValue. This can lead to unexpected behavior or crashes if the JavaScript garbage collector collects the callback, since the watcher holds a strong reference to a JSValue that might no longer be valid.

To improve stability and prevent potential memory issues, these watchers should store callbacks using JSManagedValue. JSManagedValue allows the JavaScriptCore garbage collector to manage the lifecycle of the JS objects safely while still keeping a weak reference from Swift, ensuring that callbacks remain valid for the lifetime of the watcher without creating retain cycles.

This change would make the watcher system more robust and safer in scenarios where callbacks are added and removed dynamically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions