Quote:
Originally Posted by linkpad
It's that way because it use less ressource, here an example :
If you have 100 users online, that mean you will have 100 instance of AttackManager, with my method when the packet is handled and the function RocketAttack is called, the code is executed then it's garbage collected.
|
Actually you can't garbage collect code (I know you didn't mean that but you said it in a confusing way). Your code is executed. It might get some references to class instances and the reference counter for that instance is increased. Once you leave the scope where you acquired that reference to the instance the reference counter will be decreased again. If the reference counter is 0 the object will be garbage collected on the next run of the gc. But most of the time those objects (Map, Session for example) are kept alive somewhere in a List/Dictionary in one of the managers so there will be nothing which gets collected after a function. Just at disconnects garbage collection will actually be effective. But yes creating a new MovementManager like cryz does is slower than yours. Just wanted to correct the gc part.
In case someone wants to know how that reference counting works: Look at some c++ shared_ptr implementations. The only difference to the .net version is that the c++ version will collect it instantly.