ClearMode Enum

Summary

This enum allows control over how data is treated when internal arrays are returned to the ArrayPool. Be careful to understand what each option does before using anything other than the default of Auto.
Namespace
Avalonia.Collections.Pooled
Interfaces
  • IComparable
  • IFormattable
  • IConvertible
Base Types
  • object
  • ValueType
  • Enum
graph BT Type-->Base0["Enum"] Base0-->Base1["ValueType"] Base1-->Base2["object"] Type-.->Interface0["IComparable"] Type-.->Interface1["IFormattable"] Type-.->Interface2["IConvertible"] Type["ClearMode"] class Type type-node

Syntax

public enum ClearMode

Fields

Name Constant Value Summary
Always 1
The

Always
setting has the effect of always clearing user types before returning to the pool. This is the default behavior on .NET Standard.

You might want to turn this on in a .NET Core project if you were concerned about sensitive data stored in value types leaking to other pars of your application.

static
Auto 0

Auto
has different behavior depending on the host project's target framework.

.NET Core 2.1: Reference types and value types that contain reference types are cleared when the internal arrays are returned to the pool. Value types that do not contain reference types are not cleared when returned to the pool.

.NET Standard 2.0: All user types are cleared before returning to the pool, in case they contain reference types. For .NET Standard, Auto and Always have the same behavior.

static
Never 2

Never
will cause pooled collections to never clear user types before returning them to the pool.

You might want to use this setting in a .NET Standard project when you know that a particular collection stores only value types and you want the performance benefit of not taking time to reset array items to their default value.

Be careful with this setting: if used for a collection that contains reference types, or value types that contain reference types, this setting could cause memory issues by making the garbage collector unable to clean up instances that are still being referenced by arrays sitting in the ArrayPool.

static

Extension Methods