tags:

views:

308

answers:

2

There is some articles about How to get object size in memory ? but they does not explain how to get the size of an object in memory.

when I use:

System.Runtime.InteropServices.Marshal.SizeOf(arrayListObject)

i get error:

Type 'System.Collections.ArrayList' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.

I also can not get the amount of all free memory, becouse i want to perform this calculation on web applications with a lot of threads, so a need to know exactly how much memory needs specific object.

+1  A: 

If you want to know this because of possible optimizations: Use a memory profiler.

winSharp93
no, i don't want to know it for optimization, I want to know when my DataTable grows to much, to fire an event...
Alexei.Ozon
+1  A: 

You want to find out the size in memory of managed objects in code - according to this blog entry, it is not possible.

You need to use a memory profiler to do this (like the Ants profiler).

Oded
I dont want to use profiler, i need to know the size to fire an alert/event or something
Alexei.Ozon