Skip to content

Commit 9a35ffc

Browse files
Fix: Add __del__ method to SlidingWindow for explicit memory cleanup
1 parent d452bdb commit 9a35ffc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pyeyesweb/data_models/sliding_window.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, max_length: int, n_columns: int):
5858
raise ValueError(f"n_columns must be positive, got {n_columns}")
5959

6060
# Reasonable limits to prevent memory exhaustion
61-
if max_length > 10_000_000: # 10 million samples
61+
if max_length > 10_000_000: # Have added 10 million samples
6262
raise ValueError(f"max_length too large ({max_length}), maximum is 10,000,000")
6363
if n_columns > 10_000: # 10k features
6464
raise ValueError(f"n_columns too large ({n_columns}), maximum is 10,000")
@@ -74,6 +74,18 @@ def __init__(self, max_length: int, n_columns: int):
7474
self._start = 0
7575
self._size = 0
7676

77+
def __del__(self):
78+
"""Clean up allocated numpy arrays when the object is destroyed.
79+
80+
This helps ensure memory is released promptly rather than waiting
81+
for Python's garbage collector.
82+
"""
83+
# Explicitly delete numpy arrays to free memory
84+
if hasattr(self, '_buffer'):
85+
del self._buffer
86+
if hasattr(self, '_timestamp'):
87+
del self._timestamp
88+
7789
def append(self, samples: Union[np.ndarray, list], timestamp: Optional[float] = None) -> None:
7890
"""
7991
Append a new sample to the sliding window.

0 commit comments

Comments
 (0)