Dynamic Memory Analyzer
Comprehensive memory management analysis for ace_engine codebase covering 17 critical scenarios.
Quick Start
Use this skill to analyze memory management in ace_engine codebase:
-
Statistical Analysis - Get overview metrics
- Run:
bash scripts/stats.sh <target-directory> - Review the output statistics
- Run:
-
Pattern Detection - Identify specific issues
- See PATTERNS.md for detection rules
- Execute relevant grep/awk commands from the patterns
-
Generate Report - Document findings
- Use REPORT_TEMPLATE.md as guide
- Apply recommendations from FIXES.md
Core Scenarios
1. Basic Pairing
new/deletepairingnew[]/delete[]pairing- Execution path coverage
2. Smart Pointers
- RefPtr usage patterns
- WeakPtr for cycles
- Raw/RefPtr mixing
3. Exception Safety
- Exception paths
- RAII patterns
- Try-catch coverage
4. Ownership Transfer
- Function returns
- Parameter passing
- Cross-module transfer
5. Container Pointers
- STL containers
- Cleanup logic
- Iterator safety
6. Singletons
- Singleton leaks
- Global pointers
- Static members
7. Callbacks
- EventHub callbacks
- Lambda captures
- Async cleanup
8. Multi-threading
- Cross-thread pointers
- Async tasks
- Thread-safe delete
9. Cross-layer
- Bridge layer
- FrameNode/UINode
- Pattern/RenderNode
10. Third-party
- Rosen pointers
- Skia pointers
- V8/ArkTS pointers
11. Special Patterns
- Factory pattern
- Builder pattern
- Observer pattern
12. Common Leaks
- Constructor/destructor
- Conditional branches
- Exception paths
- Loop issues
13. nullptr Handling
delete nullptrsafety- Unnecessary checks
new(std::nothrow)
14. Register/Unregister
- Registration pairing
- Exception safety
- Duplicate handling
15. Lifecycle Binding
- Parent/child cleanup
- Circular references
- FrameNode lifecycle
16. Assignment Updates
- Member assignment
- Exception safety
- Self-assignment
17. Function Returns
- Early returns
- Multiple paths
- CheckNull cleanup
Detailed Guidance
Statistical Analysis
See STATISTICS.md for comprehensive metrics and interpretation.
Pattern Detection
See PATTERNS.md for detection rules and examples.
Fix Recommendations
See FIXES.md for code examples and best practices.
Report Template
See REPORT_TEMPLATE.md for report structure.
Severity Levels
- π΄ Critical: Definite leaks, double delete, use-after-free
- π High: Likely leaks, exception-unsafe, missing cleanup
- π‘ Medium: Potential leaks, unclear ownership, inconsistent patterns
- π’ Low: Style issues, unnecessary checks, documentation gaps
Tools
Static Analysis
# clang-tidy
clang-tidy --checks=-*,clang-analyzer-* frameworks/**/*.cpp
# cppcheck
cppcheck --enable=all frameworks/
# Custom scripts
bash scripts/stats.sh
bash scripts/detect_patterns.sh
Runtime Detection
# AddressSanitizer
ASAN_OPTIONS=detect_leaks=1 ./test_executable
# LeakSanitizer
LSAN_OPTIONS=suppressions=lsan.supp ./test_executable
# Valgrind
valgrind --leak-check=full ./test_executable
Best Practices
β Always Do
- Use RefPtr/WeakPtr for ownership
- Use MakeRefPtr for creation
- Use CHECK_NULL_* macros
- Implement proper destructors
- Use RAII for resources
- Document ownership for returns
- Use WeakPtr to break cycles
β Never Do
- Delete RefPtr-managed pointers
- Forget to delete raw pointers
- Use delete instead of delete[]
- Mix raw/RefPtr without clear ownership
- Skip delete on exception paths
- Create RefPtr cycles
- Assume third-party ownership
β οΈ Be Careful
- Exception safety in new/delete pairs
- Ownership transfer across boundaries
- Callback memory management
- Cross-thread pointer sharing
- Container pointer cleanup
- Third-party library ownership