c# - GC taking more then 70% of total time -


i have code dynamically creates instances of unknown type using expression-trees.

public ienumerable<t> createmany<t>(int number, params object[] args) {     var activator = getactivator<t>(args);      list<t> result = new list<t>();     (int = 0; < number; i++) result.add(activator.createinstance<t>(args));     return result; } 

the getactivator-method returns delegate (activator) constructor of type t matches given args.

within second class have code activator (the delegate):

public static class generictypefactory {      /// <summary>     /// delegate constructor     /// </summary>     public delegate object activator(params object[] args);      public static t createinstance<t>(this activator activator, params object[] args)     {         // call delegate (that points constructor)         return (t)activator(args);     } 

when running dottrace multiple times notice when executing createmany-method more 70% of time gc running (where cannot further dig in dottrace). i´m not sure references come , why gc allways releases them @ same time (allways when running particular method). has idea why may happen?


Comments