Wednesday, December 15, 2010

Why don't reference types go on the stack?

When I was in school I was taught that heap allocation was expensive and stack allocation was cheap.
I was learning C / C++ at the time and that was (and is) true for C / C++.
This is not the case for C#...allocation to the stack and heap is about the same, thanks to the magic sauce of garbage collection.

Check out this 2 part post by Eric Lippert on his blog for an interesting read about what you thought you knew about value and reference types.
http://blogs.msdn.com/b/ericlippert/archive/2009/04/27/the-stack-is-an-implementation-detail.aspx

No comments:

Post a Comment