Skip to content

Commit

Permalink
Fix state update on unmounted heap usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jan 11, 2024
1 parent f251949 commit 607aa5e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/console/src/HeapUsage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Tooltip } from '@deephaven/components';
import type { QueryConnectable } from '@deephaven/jsapi-types';
import { Plot, useChartTheme } from '@deephaven/chart';
import Log from '@deephaven/log';
import { useAsyncInterval } from '@deephaven/react-hooks';
import { useAsyncInterval, useIsMountedRef } from '@deephaven/react-hooks';
import './HeapUsage.scss';

const log = Log.module('HeapUsage');
Expand Down Expand Up @@ -41,9 +41,16 @@ function HeapUsage({
usages: [],
});

const isMountedRef = useIsMountedRef();

const setUsageUpdateInterval = useCallback(async () => {
try {
const newUsage = await connection.getWorkerHeapInfo();

if (!isMountedRef.current) {
return;
}

setMemoryUsage(newUsage);

if (bgMonitoring || isOpen) {
Expand All @@ -69,7 +76,7 @@ function HeapUsage({
} catch (e) {
log.warn('Unable to get heap usage', e);
}
}, [isOpen, connection, monitorDuration, bgMonitoring]);
}, [connection, isMountedRef, bgMonitoring, isOpen, monitorDuration]);

useAsyncInterval(
setUsageUpdateInterval,
Expand Down

0 comments on commit 607aa5e

Please sign in to comment.