MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / useMemoryUsage

Function useMemoryUsage

source code/hooks/useMemoryUsage.ts:20–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18 * Polls every 10 seconds; returns null while status is 'normal'.
19 */
20export function useMemoryUsage(): MemoryUsageInfo | null {
21 const [memoryUsage, setMemoryUsage] = useState<MemoryUsageInfo | null>(null)
22
23 useInterval(() => {
24 const heapUsed = process.memoryUsage().heapUsed
25 const status: MemoryUsageStatus =
26 heapUsed >= CRITICAL_MEMORY_THRESHOLD
27 ? 'critical'
28 : heapUsed >= HIGH_MEMORY_THRESHOLD
29 ? 'high'
30 : 'normal'
31 setMemoryUsage(prev => {
32 // Bail when status is 'normal' — nothing is shown, so heapUsed is
33 // irrelevant and we avoid re-rendering the whole Notifications subtree
34 // every 10 seconds for the 99%+ of users who never reach 1.5GB.
35 if (status === 'normal') return prev === null ? prev : null
36 return { heapUsed, status }
37 })
38 }, 10_000)
39
40 return memoryUsage
41}

Callers 1

MemoryUsageIndicatorFunction · 0.85

Calls 1

useIntervalFunction · 0.85

Tested by

no test coverage detected