Ross Coded Classes

Programming tips with no rose colored glasses.

Create Less Garbage with EventArgs.Empty

Create less garbage in memory by using EventArgs.Empty instead of new EventArgs().  There are other framework classes that have similar static methods, like StringComparer.InvariantCultureIgnoreCase.
 
Whenever you need to pass an EventArgs instance to something, don’t construct a new EventArgs().  Instead, use EventArgs.Empty.  I have observed certain actions in previous releases of Infragistics UltraGrid that created several hundred thousand EventArgs objects per second, adding stress to the garbage collector.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.