A good way to get to know how much memory your object eats is using GetTotalMemory() method in System.GC.
long memoryStart = System.GC.GetTotalMemory(true); // Generate some of your objects ICollection<myobject> myObjects = List<myobject>(); for (int i = 0; i < 10000; i++) { myObjects.Add(new MyObject); } long memoryEnd = System.GC.GetTotalMemory(true); MessageBox.Show((memoryEnd - memoryStart).ToString());
That gives you how much memory consume 10 000 objects of your class. Divide it by 10 000 and it's the memory consumption of one object.
Thanks for the tip. Good method to check your memory consumption!
ReplyDeleteVery interesting, will bear that in mind IF i can remember it.
ReplyDeletecool info, thx for sharing
ReplyDelete