memory-leak-mointor v1.0.4
React Native Memory Leak Monitor š
š„ A powerful memory leak detection tool for React Native, inspired by LeakCanary! Monitor and catch memory leaks in real-time.
ā ļø Currently Android Only (iOS coming soon! š)
⨠Features
š Real-time memory usage monitoring
šÆ Component-level leak detection
ā±ļø Session-based memory analysis
š Zustand store integration
š± Memory metrics tracking
šØ Automatic leak notifications
š Easy-to-use HOC wrapper
š Installation
npm install memory-leak-monitor
# or
yarn add memory-leak-monitor
š¤ Android Setup
Add to android/app/build.gradle
:
dependencies {
// ... other dependencies
implementation project(':memory-leak-monitor')
}
š Basic Usage
1. š Wrap Your App
import { MonitorMemory } from "memory-leak-monitor";
function App() {
return (
<MonitorMemory
interval={1000} // Update interval in ms
sessionDurationMinutes={0.5} // Session duration
>
{/* Your app content */}
</MonitorMemory>
);
}
2. šÆ Monitor Components
import { withLeakDetection } from "memory-leak-monitor";
const MyComponent = () => {
// Your component code
};
export default withLeakDetection(MyComponent, "MyComponent");
3. š Track Memory Stats
import { useLeakDetectionStore } from "memory-leak-monitor";
function MemoryDisplay() {
const memoryInfo = useLeakDetectionStore((state) => state.memoryInfo);
return (
<View>
<Text>Used Memory: {memoryInfo?.usedMemory} MB</Text>
<Text>Available: {memoryInfo?.availableMemory} MB</Text>
</View>
);
}
š ļø API Reference
š MonitorMemory Component
<MonitorMemory
interval?: number; // Memory check interval (ms)
sessionDurationMinutes?: number; // Monitoring session duration
>
šØ withLeakDetection HOC
withLeakDetection(
WrappedComponent: React.ComponentType,
componentName: string
)
šŖ useLeakDetectionStore Hook
const {
memoryInfo, // Current memory metrics
leaks, // Detected memory leaks
startTracking, // Start tracking a component
stopTracking, // Stop tracking a component
subscribeToMemoryUpdates, // Subscribe to memory updates
} = useLeakDetectionStore();
š Memory Info Type
type MemoryInfo = {
totalMemory: number; // Total device memory (MB)
availableMemory: number; // Available memory (MB)
usedMemory: number; // Used memory (MB)
appMemory: number; // App's memory usage (MB)
isLowMemory: boolean; // Low memory warning
lowMemoryThreshold: number; // Low memory threshold (MB)
};
šÆ Detection Settings
Default thresholds for leak detection:
š Minimum memory change: 5MB
š Significant increase: 20MB
š Sustained increase window: 8 readings
š¾ System memory threshold: 50MB
š” Best Practices
- š Start monitoring early in app lifecycle
- šÆ Monitor suspicious components first
- ā±ļø Use sessions during development
- š Check memory after major UI changes
- š Monitor component mount/unmount cycles
ā ļø Limitations
- š¤ Android only (iOS coming soon!)
- š± Readings vary between devices
- š Background processes affect metrics
- šļø Garbage collection impacts results
š¤ Contributing
We love contributions! Check out our Contributing Guide for guidelines.
š License
MIT
šŖ Support
Found a bug? Have a feature request? Open an issue!
š Show Your Support
Give a āļø if this project helped you!