MemoryAllocations class

An interface for listening to object lifecycle events.

If kFlutterMemoryAllocationsEnabled is true, MemoryAllocations listens to creation and disposal events for disposable objects in Flutter Framework. To dispatch events for other objects, invoke MemoryAllocations.dispatchObjectEvent.

Use this class with condition kFlutterMemoryAllocationsEnabled, to make sure not to increase size of the application by the code of the class, if memory allocations are disabled.

The class is optimized for massive event flow and small number of added or removed listeners.


hashCode int
The hash code for this object.
hasListeners bool
Return true if there are listeners.
runtimeType Type
A representation of the runtime type of the object.


addListener(ObjectEventListener listener) → void
Register a listener that is called every time an object event is dispatched.
dispatchObjectCreated({required String library, required String className, required Object object}) → void
Create ObjectCreated and invoke dispatchObjectEvent if there are listeners.
dispatchObjectDisposed({required Object object}) → void
Create ObjectDisposed and invoke dispatchObjectEvent if there are listeners.
dispatchObjectEvent(ObjectEvent event) → void
Dispatch a new object event to listeners.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
removeListener(ObjectEventListener listener) → void
Stop calling the given listener every time an object event is dispatched.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.

Static Properties

instance MemoryAllocations
The shared instance of MemoryAllocations.