View in #prefect-community on Slack
@Ling_Chen: Hi Community! Are there guidelines to free up the previous tasks’ memory after they are finished? We are running memory intensive pipelines and run into out of memory error. The output of each task is only needed in the next task, but not in the subsequent tasks. Is there room for memory optimization?
@Kevin_Kho: You can persist the data and then just pass the location downstream to be loaded in. Are you doing that already?
@Ling_Chen: When you say persist the data, are you referring to storing the data into disk and load it back in the next task?
@Kevin_Kho: yeah like
df.to_parquet so that it’s not held in memory because Prefect holds the mapped results and then you pass the location string instead of the df.
@Ling_Chen: Cool. I can do that. But just to understand Prefect a bit better, there is no easy way to clear the memory of task outputs? So python gc.collect has no effect on task outputs?
@Anna_Geller: Lastly, you can always simply delete Python objects if you no longer need them:
@Ling_Chen: Cool cool. Something like del df and gc.collect() should work then. Thanks!
@Anna_Geller: Looks like SO Python folks also recommend just that
Stack Overflow: How can I explicitly free memory in Python?