Jump to content
Posted 24 October 2012 - 09:54 PM
Posted 25 October 2012 - 05:51 AM
Posted 25 October 2012 - 06:17 AM
Posted 25 October 2012 - 08:29 AM
Posted 25 October 2012 - 11:35 AM
Hey so in the past I've been very interested in making simulations of evolving interesting behaviors between artificial intelligent agents. Obviously this sort of simulation is a whole lot of creating populations, killing them, creating more, killing them over and over. I've always had this problem, though, where as the program would run it would slowly get more and more laggy, until maybe thirty minutes into the simulation the lag would be so bad I'd have to stop it altogether. I've heard of this thing called "garbage collection" and suspect that is the issue, but I've got no idea what it entails. Does anyone have any advice to offer?
Edited by ATC, 25 October 2012 - 11:36 AM.
Posted 25 October 2012 - 09:50 PM
Posted 26 October 2012 - 01:30 AM
Posted 27 October 2012 - 12:51 PM
This is symptomatic of using Event Handlers but not unhooking them. Its a common mistake to make if you are new to .net. Look for any event handlers you hook up and make sure you are unhooking them deliberately at some stage. What tends to happen is they get hooked at some stage but never unhooked. This means that the class that has the event declaration has references to all those classes that hook that event, and if that event raising class is a static or long lived class, the classes that are hooking its events never get released to be GC'd - and even worse continue to have events raised on them long after their utility has gone.
This might not be precisely your problem but its a common anti-pattern that leads to memory loss and laggy behaviour in .net systems of all kinds.