Hi,
Can this be any help? python - Deleting variable does not erase its memory from RAM memory - Stack Overflow
Eg
import numpy as np
import gc
a = np.array([1,2,3])
del a
gc.collect()
In your case it will look like this
def consume_memory(num):
# Create a list to hold many MemoryConsumer objects
objects = []
# Create 1 million objects, each consuming a significant amount of memory
for i in range(num):
objects.append(create_asset(1000))
# Explicitly delete the list
del objects
# Manually trigger garbage collection
import gc
gc.collect()
return ("Created a lot of objects to consume memory.")
But i guess that you want to return the list called objects in the consume_memory method?
Perhaps it is worth a try to make the list called objects a global variable, and move the deletion of the variable and the trigger of empty the garbage collector after you are done working with the data. Perhaps not optimal, but its worth a try for starters ![]()