c# - How to measure memory usage of a code? -


i'm trying measure memory usage of code, don't know how proceed. don't want use "dotmemory" or "profiler" need programming.

there way know how object allocated ? 5 int(4 bytes) + 4 object (16 bytes) ...

i used

process.workingset64

but every time run same code different values.

so best way measure memory usage of code ?

.net managed memory environment. means allocation , deallocation handled transparently you, means memory usage patterns aren't entirely deterministic.

99.9% of time, isn't issue @ all. rest of time, should focus work on area matters - usually, it's pretty easy handle critical load in 1 place.

your question suggests come c/pascal background - tradeoff of managed memory shoudln't care memory - sure, want pay attention not outright waste memory, taking twice memory strictly necessary isn't thing lose sleep about. "memory before" , "memory after" question doesn't make sense in multi-threaded environment - method isn't 1 that's running in meantime.


Comments