I am facing a memory leak, it is happening in a thread. My code structure looks like this
while True:
with self._lock:
if self.valid_data:
# do something
Memory leak
How to delete a list completely.
My Solutionself.__data.clear()
self.__data = []
Problem
How to clear the memory very efficiently in python for list and deque data structures?
Here, 3 consumer threads use the data and one reset thread clears the thread based on some flag.
del self.__data
or any other way?
It happens very rarely, which makes me hard to reproduce, so I am just thinking the best code will resolve the issue. Please advise.
Other approaches
- Delete an object and all references to it in Python? I need some simple API for list or deque.