Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET garbage profiling: calculate how much garbage a piece of code is making

I would like to write a utility class that will help me determine how much garbage a certain piece of code is making.

Something I can use like this: GarbageProfiler.Start(); and int numGarbage = GarbageProfiler.End();

Idea is simple enough. But does it make sense to do so? Are there any tools out there to do just this?

like image 420
Waldo Bronchart Avatar asked Nov 15 '22 02:11

Waldo Bronchart


1 Answers

But does it make sense to do so?

No.

You would at least have to differentiate between the Generations of the garbage.

The memory that a certain piece of code allocates and still holds at the end is (can be) much more expensive than the objects it quickly released.

like image 184
Henk Holterman Avatar answered Nov 16 '22 22:11

Henk Holterman