Killing agents but they slow down the run, maybe?

Skip to first unread message

Andreas Pape

Sep 30, 2020, 8:12:13 PM9/30/20
Hi mesaheads. I have a model which visually implements a genetic algorithm, with different agents being different genes. I kill them off and replace them. But the model slows down a lot as the generations proceed, which shouldn’t be the case (I think) unless the “dead” agents are hanging around in memory. I remove the agents from the schedule and I remove them from any other place, like the grid and my list of agents self.agents. Is there a way to get python/mesa to delete them from memory? Like force “garbage collection” or whatever?

Has anyone else encountered this?

I can also post code but it’s a lot of code.



Economics, Binghamton University

Message has been deleted


Oct 3, 2020, 6:20:35 AM10/3/20
to ProjectMesa
Hmm, without code it is a lot of guessworking, but: Yes in order to delete an object (well, at least to allow deletion of an object) you have to remove all references. Another possibility would be if you collect some data about your agents and it is just the datacollector that increases in size!?
Would be best if you could share some code (e.g. as a github gist)

Andreas D Pape

Oct 6, 2020, 1:08:21 PM10/6/20
to ProjectMesa
Hello. I just wanted to share the solution. It was, in fact, data collection; and it wasn't just the self.datacollector.collect() statement, but the instantiation of the datacollector object in the first place. Presumably it retains references to agents after I remove them from the schedule? In any case, once I removed that, there was absolutely no slowdown.

Thanks everyone.

Jacqueline Kazil

Oct 6, 2020, 1:49:21 PM10/6/20
to Andreas D Pape, ProjectMesa
Thank you sharing!

Project repos:
You received this message because you are subscribed to the Google Groups "ProjectMesa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Jacqueline Kazil | @jackiekazil 

Reply all
Reply to author
0 new messages