@usefy/use-memory-monitor 0.0.34 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -340,6 +340,31 @@ function LeakDetector() {
|
|
|
340
340
|
}
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
+
#### How Leak Detection Works
|
|
344
|
+
|
|
345
|
+
The hook uses **Linear Regression Analysis** to detect memory leaks:
|
|
346
|
+
|
|
347
|
+
1. **Data Collection**: Collects memory samples over time (configurable via `sampleSize`)
|
|
348
|
+
2. **Linear Regression**: Applies least squares regression to find the best-fit line through the memory data points
|
|
349
|
+
3. **Slope Analysis**: The slope indicates memory growth rate (bytes per sample)
|
|
350
|
+
4. **R² Coefficient**: Measures how well the data fits the linear model (0-1, higher = more consistent growth)
|
|
351
|
+
5. **Probability Calculation**: Combines slope and R² to calculate leak probability
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
Leak Probability = f(slope, R², sensitivity)
|
|
355
|
+
|
|
356
|
+
- High slope + High R² = High probability (consistent memory growth)
|
|
357
|
+
- High slope + Low R² = Lower probability (fluctuating memory)
|
|
358
|
+
- Low slope = Low probability (stable memory)
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Sensitivity Levels:**
|
|
362
|
+
| Sensitivity | Min Slope | Min R² | Description |
|
|
363
|
+
|-------------|-----------|--------|-------------|
|
|
364
|
+
| `low` | 10KB/sample | 0.8 | Only detects obvious leaks |
|
|
365
|
+
| `medium` | 5KB/sample | 0.6 | Balanced detection (default) |
|
|
366
|
+
| `high` | 1KB/sample | 0.4 | Detects subtle leaks |
|
|
367
|
+
|
|
343
368
|
### Threshold Alerts
|
|
344
369
|
|
|
345
370
|
```tsx
|
package/package.json
CHANGED