About dart-memory
A Dart memory-management skill for mobile developers. It covers resource lifecycles, allocation pressure, isolates, image sizing, leak investigation, and handling large datasets without loading them all at once.
Key features
- 01Dispose lifecycle-bound resources
- 02Reduce short-lived allocations
- 03Move heavy work to isolates
- 04Limit image memory use
- 05Inspect leaks with DevTools
- 06Paginate or stream large data
Use cases
- 01Preventing leaks when screens close
- 02Reducing jank from frequent allocations
- 03Keeping heavy processing off the main thread
- 04Handling large files or datasets
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ dhruvanbhalara/ skills --skill dart-memoryAfter installing, type/dart-memoryin Claude Code to confirm it loaded.
Details
From the project READMEMemory Management
Mobile devices have limited RAM. Efficient memory management is critical to prevent crashes and ensure a smooth user experience.
Resource Lifecycle
- Explicit Disposal: Always close
StreamController,Timer,FocusNode, andChangeNotifierin thedispose()method. - Late Initialization: Use
lateto delay object creation until it's actually needed, reducing initial memory footprint.
Garbage Collection (GC) Pressure
- Generational GC: Dart's GC is optimized for short-lived objects. However, creating thousands of objects in a single frame can still cause jank.
- Object Re-use: Avoid creating new objects in
build()or high-frequency loops. Reuse data structures where possible. - Large Collections: Clearing a large list (
list.clear()) is better than re-assigning it to a new list if the list itself is long-lived.
Mobile Specifics
- Isolates: Use
Isolate.run()for heavy computations (JSON parsing > 1MB, image processing). This keeps the main thread free and prevents UI freezes. - Image Memory: Use
cacheWidthandcacheHeightinImage.networkorImage.assetto avoid loading high-resolution images into memory at full size. - Memory Leaks: Use the DevTools Memory View to identify "leaking" objects that stay in the heap after their context (like a screen) is closed.
Large Data Handling
- Pagination: Never load entire datasets into memory. Use server-side or local database pagination (Isar, SQLite).
- Streaming: For large files or real-time data, use
Streamto process data in chunks rather than buffering the entire content in memory.
Comments
Markdown supported