Find out how much memory is being used by an object in C#?

前端 未结 3 1623
予麋鹿
予麋鹿 2020-12-30 05:37

Does anyone know of a way to find out how much memory an instance of an object is taking?

For example, if I have an instance of the following object:



        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 06:16

    The CLR Profiler, which is provide free by Microsoft does a very good job at this type of thing.

    An introduction to the whole profiler can be downloaded here. Also the Patterns & Practices team put something together a while back detailing how to use the profiler.

    It does a fairly reasonable job at showing you the different threads and objects created in those threads.

    Hope this sheds some light. Happy profiling!

提交回复
热议问题