243 examples
Memory leak
Unused memory accumulates without proper release.
[ FAQ1 ]
What is a memory leak?
A memory leak happens when allocated memory remains occupied indefinitely due to improper memory management, preventing the memory from being reused by the program. In languages like C or C++, this typically results from forgetting to explicitly free allocated heap memory. In languages with automatic garbage collection, like Java or JavaScript, memory leaks occur when lingering references (retain cycles) prevent objects from being garbage-collected. Over time, these leaks accumulate, gradually consuming available memory, reducing performance, and potentially causing application crashes or system instability.
[ FAQ2 ]
How to fix a memory leak
To fix memory leaks, first identify leaks using profiling tools such as Valgrind, Instruments, or built-in developer tools provided by your runtime environment. In manual memory management languages (e.g., C or C++), ensure all allocated heap memory is explicitly freed when no longer needed. For garbage-collected languages, break retain cycles by properly nullifying or removing object references to allow automatic garbage collection to reclaim unused memory. Additionally, follow good programming practices, such as using smart pointers in C++ or minimizing unnecessary object creation in Java, to proactively prevent leaks. Regularly profiling your application helps detect leaks early, preserving performance and system stability.
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup mechanism
diff block
greptile
logic: eslintCache is declared at module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Cache is stored in module-level variables - could lead to memory leaks in long-running processes since it's never cleared
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: potential memory leak - missing cleanup function to remove click event listener
suggested fix
+ const handleClick = () => {
+ setShowSurvey(!showSurvey)
+ }
+ addEventListener(widget, 'click', handleClick)
+ widget?.setAttribute('PHWidgetSurveyClickListener', 'true')
+ return () => {
+ widget?.removeEventListener('click', handleClick)
+ }
+ }
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: Unsubscribe is using onInitializeMetric for both routes but _onGetMetricState was used for subscription. This mismatch could cause memory leaks.
suggested fix
const unsubscribeToMetricEvents = useMemoizedFn(({ metricId }: { metricId: string }) => {
busterSocket.off({
route: '/metrics/get:updateMetricState',
+ callback: _onGetMetricState
});
busterSocket.off({
route: '/metrics/update:updateMetricState',
+ callback: _onGetMetricState
});
});
diff block
greptile
logic: The eslintCache is populated with null values but never cleaned up, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
diff block
greptile
logic: eslintCache is module-level and persists between runs - could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
style: Potential memory leak - eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles array is spread twice unnecessarily. Use await listChangedFiles() directly.
suggested fix
+ changedFiles = await listChangedFiles();
changedFiles.forEach(file => {
diff block
greptile
logic: Cache is stored in module-level variables which persist between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup mechanism
diff block
greptile
style: The eslintCache is initialized but never cleared between runs. Consider adding a mechanism to reset or limit the cache size to prevent memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is not cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
style: gaussian_kernel function should be a private member of TGAImage to prevent memory leaks if called directly
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup mechanism
diff block
greptile
logic: eslintCache is declared but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: Cache is populated but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Event listeners are attached in constructor but never removed. Need to implement cleanup in stop() or destructor to prevent memory leaks.
suggested fix
constructor() {
super();
+ this.handleKeydown = (e: UiohookKeyboardEvent) => this.emit('keydown', e);
+ this.handleInput = (e: UiohookKeyboardEvent) => this.emit('input', e);
+ this.handleKeyup = (e: UiohookKeyboardEvent) => this.emit('keyup', e);
+ this.handleClick = (e: UiohookMouseEvent) => this.emit('click', e);
+ this.handleWheel = (e: UiohookWheelEvent) => this.emit('wheel', e);
+ this.handleMouseup = (e: UiohookMouseEvent) => this.emit('mouseup', e);
+ this.handleMousedown = (e: UiohookMouseEvent) => this.emit('mousedown', e);
+ this.handleMousemove = (e: UiohookMouseEvent) => this.emit('mousemove', e);
+ uIOhook.on('keydown', this.handleKeydown);
+ uIOhook.on('input', this.handleInput);
+ uIOhook.on('keyup', this.handleKeyup);
+ uIOhook.on('click', this.handleClick);
+ uIOhook.on('wheel', this.handleWheel);
+ uIOhook.on('mouseup', this.handleMouseup);
+ uIOhook.on('mousedown', this.handleMousedown);
+ uIOhook.on('mousemove', this.handleMousemove);
}
diff block
greptile
logic: setTimeout without cleanup could cause memory leaks if component unmounts before timeout completes. Consider using useEffect with cleanup.
suggested fix
+ onActorLoaded={(actor) => {
+ const timeoutId = setTimeout(() => {
+ actor.setAnimation('wave')
// If the data processing popover is present, make the hedgehog face towards that bubble
// Otherwise, make it face left, which looks better in the side panel
actor.direction = dataProcessingAccepted ? 'left' : 'right'
+ }, 100)
+ return () => clearTimeout(timeoutId)
+ }}
diff block
greptile
logic: toolCallControllers map is never cleaned up - potential memory leak if tool calls accumulate
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
suggested fix
+ if (onlyChanged && changedFiles === null) {
try {
+ // Clear previous cache before new run
+ eslintCache.clear();
changedFiles = [...await listChangedFiles()];
changedFiles.forEach(file => {
if (!eslintCache.has(file)) {
eslintCache.set(file, null);
}
});
} catch (error) {
console.error('Error getting changed files:', error);
throw error;
}
}
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: Memory leak potential - the eslintCache grows indefinitely as new files are checked. Consider implementing a cache clearing mechanism.
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
suggested fix
changedFiles = [...await listChangedFiles()];
+ // Clear old entries and only keep current changed files
+ eslintCache = new Map();
changedFiles.forEach(file => {
eslintCache.set(file, null);
});
diff block
greptile
logic: Cache stored in module-level variables will persist between runs and could cause memory leaks. Consider implementing cache clearing mechanism.
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: Missing cleanup function in useEffect - could lead to memory leaks if component unmounts during async operation
diff block
greptile
logic: The timeout Promise should be cleared when the command completes to prevent memory leaks
```suggestion
+ const timeoutId = setTimeout(() => reject(new Error(`Command timed out after ${timeout}ms: ${fullCommand}`)), timeout);
const requestPromise = Promise.race([
+ executeCommand(fullCommand, cacheKey, maxRetries).finally(() => clearTimeout(timeoutId)),
new Promise((_, reject) => {
+ timeoutId;
}),
]);
```
diff block
greptile
logic: Memory leak potential - cache grows indefinitely as new files are checked. Consider implementing cache cleanup for removed files.
diff block
greptile
logic: Event listeners are added but never removed, which could cause memory leaks
suggested fix
useEffect(() => {
window.addEventListener('mousemove', windowMouseMoveHandler)
window.addEventListener('mouseup', windowMouseUpHandler)
+ return () => {
+ window.removeEventListener('mousemove', windowMouseMoveHandler)
+ window.removeEventListener('mouseup', windowMouseUpHandler)
}
+ }, [])
diff block
greptile
style: Global variables could cause memory leaks across multiple runs. Consider clearing eslintCache when changedFiles is reset.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is not cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is created but never cleared or persisted between runs. This could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: Cache is stored in module-level variables which persist between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared at module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: The eslintCache is stored in module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: connectToWebSocket method creates a WebSocket instance but never stores or cleans it up, leading to potential memory leaks
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is not cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
style: Memory leak potential - changedFiles array is spread twice unnecessarily. Use direct assignment instead.
suggested fix
+ changedFiles = await listChangedFiles();
changedFiles.forEach(file => {
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is declared at module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Missing cleanup of debounced handleScroll function which could cause memory leaks
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - changedFiles array is spread twice unnecessarily. Consider removing the spread operator here.
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
logic: Cache is stored in module-level variables which persist between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: fetchReleases should be wrapped in an AbortController to handle component unmounting and prevent memory leaks
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
style: Global mutable state (changedFiles and eslintCache) could cause memory leaks in long-running processes. Consider moving to function scope or implementing cache clearing.
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: The eslintCache is initialized but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
style: Global mutable state could cause memory leaks in long-running processes since the cache is never cleared
diff block
greptile
style: Global variables could cause memory leaks across multiple runs. Consider clearing eslintCache when changedFiles is reset.
diff block
greptile
logic: eslintCache is module-level and persists between runs - could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
style: Cache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is stored in module scope but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
style: Cache is stored in module-level variables which persist between runs. This could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - cache grows indefinitely as new files are checked. Consider adding cache invalidation strategy.
diff block
greptile
logic: Cache entries are never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is stored in module scope but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: Consider cleaning up the setTimeout (e.g., using a ref and clearing it on unmount) to avoid potential memory leaks.
diff block
greptile
logic: eslintCache is declared globally but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
style: Cache entries are never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: missing cleanup function in useEffect and missing telemetry in dependency array - could cause memory leaks or stale closures
diff block
greptile
logic: readline interface is never closed with rl.close(). This could cause memory leaks.
diff block
greptile
logic: Memory leak potential: changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is stored in module scope but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
suggested fix
changedFiles = [...await listChangedFiles()];
+ // Clear old entries before adding new ones
+ eslintCache.clear();
changedFiles.forEach(file => {
eslintCache.set(file, null);
});
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is using module-level state which could cause memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
style: Global mutable state (changedFiles and eslintCache) could cause memory leaks in long-running processes. Consider moving cache into the function scope or implementing cache clearing.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Consider clearing it when appropriate to prevent memory leaks in long-running processes.
diff block
greptile
logic: The unsubscribeReject function is created but not called if the rejectEventType event occurs and the promise is rejected. This could lead to a memory leak as the event listener would remain active.
suggested fix
public untilEvent<TEvent extends Event<State, CustomEvent>>(
resolveEventType: TEvent['type'],
rejectEventType?: TEvent['type']
): Promise<{ event: TEvent; eventInfo: EventInfo }> {
return new Promise<{ event: TEvent; eventInfo: EventInfo }>((resolve, reject) => {
const unsubscribeResolve = this.subscribe(resolveEventType as any, (event, eventInfo) => {
unsubscribeResolve();
+ if (unsubscribeReject) unsubscribeReject();
resolve({ event, eventInfo } as any);
});
+ let unsubscribeReject: (() => void) | undefined;
if (rejectEventType) {
+ unsubscribeReject = this.subscribe(rejectEventType as any, (event, eventInfo) => {
+ unsubscribeReject?.();
unsubscribeResolve();
reject({ event, eventInfo } as any);
});
}
});
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: Cache is stored in module-level variables which persist between runs. This could lead to memory leaks in long-running processes.
diff block
greptile
logic: The eslintCache is stored in module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: eslintCache is never cleared between runs, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache and changedFiles are module-level variables that persist between runs, which could cause memory leaks in long-running processes
diff block
greptile
style: Memory leak potential - the eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism or size limit.
diff block
greptile
logic: The eslintCache is stored in module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - cache grows indefinitely without cleanup mechanism
suggested fix
changedFiles = [...await listChangedFiles()];
+ // Clear old entries before adding new ones
+ eslintCache.clear();
changedFiles.forEach(file => {
eslintCache.set(file, null);
});
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared at module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared - could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Modal container creation and cleanup could cause memory leaks if story is rendered multiple times. Consider moving modalContainer to a shared context or ref.
diff block
greptile
logic: eslintCache is never cleared between runs, could lead to memory leaks in long-running processes
diff block
greptile
logic: The eslintCache is stored in a module-level variable but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - the eslintCache grows indefinitely without cleanup. Consider implementing a cache clearing mechanism or size limit.
diff block
greptile
logic: eslintCache is declared globally but never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
style: setTimeout with async callback can cause memory leaks if component unmounts. Consider useEffect cleanup
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Cache is populated but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - cache grows indefinitely as new files are checked. Consider implementing a cache cleanup mechanism.
diff block
greptile
logic: eslintCache is never cleared between runs, could lead to memory leaks in long-running processes
diff block
greptile
style: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
diff block
greptile
logic: eslintCache is using module-level state which could cause memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
diff block
greptile
style: Memory leak potential - the eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: Global mutable state (changedFiles and eslintCache) could cause memory leaks in long-running processes. Consider clearing the cache periodically or moving to a more scoped implementation.
diff block
greptile
logic: Storage map removal is commented out - this could lead to memory leaks if old entries aren't properly cleaned up
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - cache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Global state variables could cause memory leaks in long-running processes since the cache is never cleared
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs - could cause memory leaks in long-running processes
diff block
greptile
style: Memory leak potential - the eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: The eslintCache is stored in module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
style: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
diff block
greptile
logic: eslintCache is stored in module scope but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
style: Potential memory leak - cache grows indefinitely as new files are added but never cleared. Consider implementing a cache cleanup mechanism.
diff block
greptile
logic: eslintCache is declared but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared at module level but never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared but never cleared, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is declared at module scope but never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is module-level and persists between runs. This could cause memory leaks in long-running processes.
diff block
greptile
logic: The eslintCache is stored in module scope but never cleared. This could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared at module scope but never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak risk: eslintCache grows indefinitely without cleanup. Consider implementing a cache clearing mechanism.
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely as new files are added but never cleared.
diff block
greptile
logic: Memory leak potential - the eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism or size limit.
diff block
greptile
logic: eslintCache is declared globally but never cleared, which could lead to memory leaks in long-running processes
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is never cleared between runs, could lead to memory leaks in long-running processes
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
style: Memory leak potential - eslintCache grows indefinitely without cleanup mechanism
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could lead to memory leaks in long-running processes.
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - the eslintCache grows indefinitely without cleanup. Consider adding a cache clearing mechanism.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely. Consider clearing old entries periodically.
diff block
greptile
logic: Global variables could cause memory leaks across multiple runs. Consider clearing changedFiles and eslintCache when the module is reloaded.
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
logic: changedFiles and eslintCache are module-level variables that persist between runs. This could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is declared but never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and never cleared. Could lead to memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - the eslintCache grows indefinitely without cleanup
suggested fix
+ // Clear cache for files that are no longer changed
+ eslintCache.clear();
changedFiles = [...await listChangedFiles()];
changedFiles.forEach(file => {
if (!eslintCache.has(file)) {
eslintCache.set(file, null);
}
});
diff block
greptile
logic: Memory leak potential - eslintCache grows indefinitely as new files are processed but entries are never removed
diff block
greptile
logic: eslintCache is never cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
style: potential memory leak - eslintCache grows unbounded without cleanup
diff block
greptile
logic: eslintCache is stored in module scope but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could cause memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is initialized but never cleared between runs, which could lead to memory leaks in long-running processes.
diff block
greptile
logic: eslintCache is module-level and persists between runs. Could lead to memory leaks in long-running processes.
diff block
greptile
style: Memory leak potential - eslintCache grows indefinitely as new files are processed. Consider implementing a cache clearing mechanism.
diff block
greptile
logic: Memory leak potential - changedFiles and eslintCache are never cleared between runs
diff block
greptile
logic: Consider adding a cleanup function in the useEffect to abort the controller on unmount. This prevents potential memory leaks or unwanted fetch continuations.
```suggestion
useEffect(() => {
async function fetchFastGPTAnswer() {
try {
setIsLoading(true);
const controller = new AbortController();
const result = await searchWithFastGPT(props.query, apiKey, controller.signal);
if (result) {
setAnswer(result.content || "");
setReferences(result.references || []);
}
} catch (err) {
console.error("Error fetching FastGPT answer:", err);
setError(`Failed to get answer: ${err}`);
} finally {
setIsLoading(false);
}
}
fetchFastGPTAnswer();
+ return () => controller.abort();
}, [props.query, apiKey]);
```
diff block
greptile
logic: eslintCache is not cleared between runs, which could lead to memory leaks in long-running processes
diff block
greptile
logic: No cleanup of polling timeout when component unmounts. Add cleanup in beforeUnmount event to prevent memory leaks.
suggested fix
loadDataWarehouseSavedQueriesSuccess: () => {
clearTimeout(cache.jobsRefreshTimeout)
cache.jobsRefreshTimeout = setTimeout(() => {
actions.loadDataWarehouseSavedQueries()
}, REFRESH_INTERVAL)
},
+ beforeUnmount: () => {
clearTimeout(cache.jobsRefreshTimeout)
},
Want to avoid this bug in your codebase? Try Greptile.
Avoid this bug!