Skip to content

[Rust] support Weak pointer for circular reference serialization #2679

@chaokunyang

Description

@chaokunyang

Feature Request

When to use Weak (Weak Reference):

  • Use when: You have a reference cycle between Rc or Arc pointers that would cause a memory leak. A Weak pointer doesn't count towards the strong reference count, allowing the data to be deallocated even if Weak pointers still exist.
  • How it works: To access the data, a Weak reference must be "upgraded" to a strong Rc or Arc reference. If the data has already been deallocated, the upgrade will fail, returning a null pointer, which is how you check for validity.
  • Example: In a doubly linked list, where each node has a next pointer (strong) and a prev pointer (weak) to avoid a circular dependency that would prevent the nodes from being deallocated

Object graph is common in languages like java/python/go, by using Rc/Arc/Weak, we can implement similiar functionalities in rust. Fory needs to support Rc/Arc/Weak serialization.

Is your feature request related to a problem? Please describe

No response

Describe the solution you'd like

Describe alternatives you've considered

No response

Additional context

#2621

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions