1.0.4 • Published 6 months ago

memory-leak-mointor v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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

  1. šŸ Start monitoring early in app lifecycle
  2. šŸŽÆ Monitor suspicious components first
  3. ā±ļø Use sessions during development
  4. šŸ“ Check memory after major UI changes
  5. šŸ”„ 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!


1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.1.0

6 months ago