DispatchSource.MemoryPressure Class

Definition

Sources of this type monitor the system memory pressure condition for state changes.

public class DispatchSource.MemoryPressure : CoreFoundation.DispatchSource
type DispatchSource.MemoryPressure = class
    inherit DispatchSource
Inheritance
DispatchSource.MemoryPressure
Inheritance
DispatchSource.MemoryPressure

Remarks

Elevated memory pressure is a system-wide condition that applications registered for this source should react to by changing their future memory use behavior, e.g. by reducing cache sizes of newly initiated operations until memory pressure returns back to normal.

However, applications should not traverse and discard existing caches for past operations when the system memory pressure enters an elevated state, as that is likely to trigger VM operations that will further aggravate system memory pressure.

var dispatchSource = new DispatchSource.MemoryPressure (
    MemoryPressureFlags.Critical | MemoryPressureFlags.Warn | MemoryPressureFlags.Normal, 
    DispatchQueue.MainQueue);

dispatchSource.SetRegistrationHandler (() => {
    Console.WriteLine ("Memory monitor registered");
});

dispatchSource.SetEventHandler (() => {
    var pressureLevel = dispatchSource.PressureFlags;
    Console.WriteLine ("Memory worning of level: {0}", pressureLevel);
    dispatchSource.Cancel ();
});

dispatchSource.SetCancelHandler (() => {
    Console.WriteLine ("Memory monitor cancelled");
});

dispatchSource.Resume ();

Constructors

DispatchSource.MemoryPressure(IntPtr)
DispatchSource.MemoryPressure(IntPtr, Boolean)
DispatchSource.MemoryPressure(MemoryPressureFlags, DispatchQueue)

Properties

Handle (Inherited from DispatchObject)
IsCanceled

Determine whether the specified source has been canceled.

(Inherited from DispatchSource)
PressureFlags

Reports the condition that was observed.

Methods

Activate() (Inherited from DispatchObject)
Cancel()

Asynchronously cancels the dispatch source.

(Inherited from DispatchSource)
Check()
Obsolete.
(Inherited from DispatchObject)
Dispose() (Inherited from DispatchObject)
Dispose(Boolean)

Releases the resources used by the DispatchSource object.

(Inherited from DispatchSource)
Equals(Object) (Inherited from DispatchObject)
GetHashCode()

Returns the hashcode for this object

(Inherited from DispatchObject)
InitializeHandle(IntPtr) (Inherited from NativeObject)
Release() (Inherited from DispatchObject)
Resume()

Resumes the dispatch source.

(Inherited from DispatchSource)
Retain() (Inherited from DispatchObject)
SetCancelHandler(Action)

Provides a cancellation handler

(Inherited from DispatchSource)
SetEventHandler(Action)

Specified a handler to execute when events are received on the dispatch source.

(Inherited from DispatchSource)
SetRegistrationHandler(Action)

Provides a registration handler

(Inherited from DispatchSource)
SetTargetQueue(DispatchQueue) (Inherited from DispatchObject)
Suspend()

Suspends the dispatch source.

(Inherited from DispatchSource)

Applies to