Skip to content

How to deterministically release TF objects #1295

Open
@ericstj

Description

@ericstj

Description

When updating to the latest TF.NET I noticed that Dispose methods were removed from types.

This seems to be done in e5dfe90#diff-fa5a105168638b6355c038d3eb3749d77f6e7c38c91bf7ec623b26cac68a8d1e

While using SafeHandles is good, that doesn't eliminate the need for Dispose. Objects which contain other objects with a Dispose method, should themselves expose a Dispose method, even if they don't have native resources to dispose. This helps callers get a deterministic Dispose rather than waiting for GC / Finalizers to run.

See https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/dispose-pattern

✓ DO implement the Basic Dispose Pattern on types containing instances of disposable types. See the Basic Dispose Pattern section for details on the basic pattern.

If a type is responsible for the lifetime of other disposable objects, developers need a way to dispose of them, too. Using the container’s Dispose method is a convenient way to make this possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions