tags:

views:

104

answers:

3

Is there a way in .net 2005 ide to find out the memory usage by variables inside a function and when their memory is made free by garbage collector.

A: 

Have you looked at this question, which has a few approaches including

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

You can look at GC.RegisterForFullGCNotification to see how to watch the garbage collector

MrTelly
That only returns the unmanaged memory size, not the managed size.
JaredPar
Actualy i was looking for something like callstack, watch etc and not by writing code. Is there any option within the IDE to track memory allocations
rahul
A: 

I'm not sure what you're asking here. If you're looking for the memory footprint of a particular object, the best way to go is WinDbg and the SOS extension.

http://msdn.microsoft.com/en-us/library/bb190764.aspx

This can give you a multitude of information about the object heap including size and generational information.

This post here goes into detail about how to use WinDbg to get the size of an object graph. It may be what you're looking for

http://www.eggheadcafe.com/articles/20060114.asp

JaredPar
Actualy i was looking for something like callstack, watch etc and not by writing code. Is there any option within the IDE to track memory allocations
rahul
@Strike, windbg is a debugger and doesn't require any code. There is no way to actually track an allocation in the IDE currently.
JaredPar
+1  A: 

For the first part of your question:

You can use a number of tools to profile the memory foot print of your application - down to individual lines of code. I can recommend the following tools:

For second part: GC in .net is not deterministic. It is called automatically when there is no free memory for the application. There is no tool which will tell you when GC has released memory back to free store.

Sesh