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.
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
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
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:
- CLR profiler (free download from Microsoft)
- ANTS Profiler from RED Gate (commercial but great GUI)
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.