c# - Does using a delegate create garbage -


I am working on a game for xbox360, using xNA I am comparing trash collector to a PC in xbox Performs very poorly in comparison to anyone, so the garbage made for minimal exposure is important for a smooth running game.

I remember that once the call to a representative is created garbage, but now no reference can be given to the representatives of the garbage collection for my life.

  Public Representative T GetValue & lt; T & gt; (T value) If there is a mistake to succeed, then the bonus points , T [] Args); Public Static T Transactions & lt; T & gt; (GetValue & lt; T & gt; Count, Ref: T Value, Paramus T [] Args) Where T: Class {T newValue = Calculation (Value, Args); Return foo (newValue); }  

My code looks quite vague at this time, only one solution I can think is to get rid of the representatives pass in those sections which handle the interface IValueCalculator, and then I can call the method on that interface, though it's not really very clean!

A representative is an object himself, so if you make a representative, perhaps for an anonymous method , And to do it in any other way, and do not submit the representative to the future context, then yes, that will produce garbage.

For example, this:

  collections. ForEach (Representative (T Items) {// do something with item});  

In this case, a new representative object has been created, but ForEach is not referenced beyond the call, and thus is eligible for garbage collection. .

However, the garbage is not generated by the calling delegates, any other method is much more than calling in the same way. For example, if you call a representative who takes a object parameter, going through a Int32 value, this value will be boxed, but It will happen if you have a general method similar in the same way.

Therefore it should be proper to use delegates, but the excessive composition of representative items will be a problem.


Edit : Here's a good article on memory management for Xbox and XNA. Note this quote:

How does one control GC latency? Like the NetCF for devices, the Xbox GC is non-generation, that means every collection is a complete collection on the managed pile. Thus, we find that GC latency is almost linear for the number of living objects ... then add the cost of convergence on it. Our benchmarks show that the difference between deep object hierarchy versus shallow people is negligible, hence it is the number of items that are important. Small things are cheap for dealing with big items.

As you can see, try to avoid making many unnecessary items, and you should do better.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -