1

In order to ensure performance, I created a Java class "product", whose objects (created by "new product()") I push through my simulation. I read about deleting agents from a population. Does it make sense to delete those objects from AnyLogic, if not needed anymore performance wise, or is there no such function for created objects of Java class?

As of right now, I just remove them from a collection, if I'm done, and don't use/call them anymore.

Captain Man
  • 6,997
  • 6
  • 48
  • 74
Lennart
  • 13
  • 3
  • This question was closed wrongly, your question is 100% valid for AnyLogic and has nothing to do with Java gc... You should always delete agents you do not need anymore. Either use a "Sink" object (if they flow through a flow chart) or do it manually using `remove_MyAgentPopulation()` if they live in a population – Benjamin Aug 08 '22 at 05:40
  • Thank you very much. I'm not entirely sure if I understood correctly, because I'm not using flow charts and function is only for agents? What if I create a new object of a javaclass, add it to a collection, for example JavaClass "Produkt": Produkt m = new Produkt () and then stock.add(m); Once the "stock" is used, i type in "stock.removeFirst()" ... is this enough or do I also have to "delete" the objects m of javaclass product? Because I will create a lot of products throughout the simulation run ... Thank you in advance :) – Lennart Aug 09 '22 at 20:35
  • For Java objects, Java takes care of deleting things, no worries on that end (its called garbage collection) – Benjamin Aug 10 '22 at 05:26
  • Great, thank you again for your big help. I wasn't sure if there is an exception for anylogic. To be sure regarding the agents: the function you stated is for an entire population? Is "removeAgentFromContents(agent)" for single agents? – Lennart Aug 10 '22 at 21:32
  • no, for populations it is `remove_MyPopulation(agenttoremove)`. Check the help on populations for more info (or open new, specific issues) – Benjamin Aug 11 '22 at 05:15

0 Answers0