1

The model I have contains huge number of agents. However, I wish to partially delete/elminate some agents who have done their job during the run-time, in order to release computing memory, speed up model execution and avoid OOM.

Is context.remove() really eliminates/kills the agent(object) permanently? Is memory released after this operation? If not, what is the correct procedure?

Jack
  • 1,339
  • 1
  • 12
  • 31

1 Answers1

3

Yes, that's right. Unless you have some other reference to the agent, removing it from the context will allow the memory to be garbage collected.

J. Ozik
  • 1,083
  • 5
  • 6
  • what do you mean by "other reference to the agent". Upon removing an agent, is it supposed to be that any relationships/reference to this agent will also be automatically cleared? – Jack Jun 25 '20 at 06:55
  • 1
    If you've created a reference to the agent, for example in a list that you maintain, removing the agent from the context would still result in the reference that you manage (the one in your list) persisting. If that's the case, the object will not be available for garbage collection unless you also remove the reference from any data structure you've created. I hope that helps clarify. – J. Ozik Jun 26 '20 at 13:46
  • many thanks for clarification. In fact, after a series of complex agent operations, sometimes it's not easy to identify the relevant reference. Are there convenient ways to spot any established relationships with an object, before removing it from the context? – Jack Jun 27 '20 at 11:53
  • 1
    I suggest to use a good profiler like YourKit (https://www.yourkit.com/) to help track object references. It can still be difficult to track object references with a profiler if there are lots of weak references like collections that reference objects. Strategic logging and debugging can help, like checking the size of lists or maps every so often to make sure they're the expected size. – Eric Tatara Jun 29 '20 at 21:54