Click here to Skip to main content
15,937,186 members
Home / Discussions / C#
   

C#

 
GeneralRe: How memory is allocated in .Net application Pin
jschell26-Feb-15 10:02
jschell26-Feb-15 10:02 
GeneralRe: How memory is allocated in .Net application Pin
Tridip Bhattacharjee26-Feb-15 21:06
professionalTridip Bhattacharjee26-Feb-15 21:06 
GeneralRe: How memory is allocated in .Net application Pin
Pete O'Hanlon27-Feb-15 7:23
mvePete O'Hanlon27-Feb-15 7:23 
GeneralRe: How memory is allocated in .Net application Pin
Tridip Bhattacharjee1-Mar-15 21:22
professionalTridip Bhattacharjee1-Mar-15 21:22 
GeneralRe: How memory is allocated in .Net application Pin
manchanx26-Feb-15 4:24
professionalmanchanx26-Feb-15 4:24 
GeneralRe: How memory is allocated in .Net application Pin
Tridip Bhattacharjee26-Feb-15 22:01
professionalTridip Bhattacharjee26-Feb-15 22:01 
GeneralRe: How memory is allocated in .Net application Pin
Pete O'Hanlon26-Feb-15 22:53
mvePete O'Hanlon26-Feb-15 22:53 
GeneralRe: How memory is allocated in .Net application Pin
OriginalGriff26-Feb-15 4:41
mveOriginalGriff26-Feb-15 4:41 
Tridip Bhattacharjee wrote:
i heard that reference type stored in heap and their corresponding value stored in stack.

No. The instance (which holds the actual values) is always on the heap: only the reference to the instance is ever on the stack.

Let's think about instances for a moment.
What is an instance?
Basically, it's a specific example of something. "Car" is a generic idea - you know what a car is, it's got an engine, four wheels, that sort of thing. But a generic idea is not something you can drive to the shops in: for that you need "this car", "that car", "your car", "my car" - these are instances of the generic idea. Consider this:
What colour is a Car?

You can't answer, because a generic idea doesn't have a colour.
What colour is your car?

That's a lot easier: "your car is red", or "your car is blue" - because now you are talking about an instance instead of the generic idea.

So in terms of variables all instances of a Car are stored on the Heap, but the references to them are stored on the stack:
C#
Car myCar = new Mercedes("Red");     // I wish, it's not even close to new...
Car yourCar = new Bugatti("Black");  // Probably...:laugh:
"myCar" and "yourCar" are the variables and they are on the stack - but the actual Cars the refer to are on the heap.

And when I change cars:
C#
myCar = new BrokenDownHeapOfJunkThatWasABMWOnce();
That only changes the reference that "myCar" held - it doesn't destroy the "old" car I used to have, it just lets it be referenced by it's new owner. If you crash your car, then I could sell you my car, to get a new one myself:
C#
yourCar.Dispose();
yourCar = myCar;
myCar = new BrokenDownHeapOfJunkThatWasABMWOnce();
The variables are the same, but the items they reference have changed.

Make sense?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: How memory is allocated in .Net application Pin
Santosh K. Tripathi2-Mar-15 17:07
professionalSantosh K. Tripathi2-Mar-15 17:07 
AnswerRe: How memory is allocated in .Net application Pin
F-ES Sitecore26-Feb-15 3:59
professionalF-ES Sitecore26-Feb-15 3:59 
GeneralRe: How memory is allocated in .Net application Pin
Tridip Bhattacharjee26-Feb-15 4:16
professionalTridip Bhattacharjee26-Feb-15 4:16 
GeneralRe: How memory is allocated in .Net application Pin
F-ES Sitecore26-Feb-15 4:42
professionalF-ES Sitecore26-Feb-15 4:42 
GeneralRe: How memory is allocated in .Net application Pin
Richard MacCutchan26-Feb-15 5:09
mveRichard MacCutchan26-Feb-15 5:09 
GeneralRe: How memory is allocated in .Net application Pin
Tridip Bhattacharjee26-Feb-15 21:03
professionalTridip Bhattacharjee26-Feb-15 21:03 
GeneralRe: How memory is allocated in .Net application Pin
Richard MacCutchan26-Feb-15 21:19
mveRichard MacCutchan26-Feb-15 21:19 
GeneralRe: How memory is allocated in .Net application Pin
Santosh K. Tripathi2-Mar-15 17:18
professionalSantosh K. Tripathi2-Mar-15 17:18 
GeneralRe: How memory is allocated in .Net application Pin
Richard MacCutchan26-Feb-15 22:30
mveRichard MacCutchan26-Feb-15 22:30 
QuestionRegarding Network buffer and datareader data fetch c# Pin
Tridip Bhattacharjee26-Feb-15 2:33
professionalTridip Bhattacharjee26-Feb-15 2:33 
GeneralRe: Regarding Network buffer and datareader data fetch c# Pin
PIEBALDconsult26-Feb-15 3:31
mvePIEBALDconsult26-Feb-15 3:31 
QuestionNeed help for auto response of a sms Pin
MA11026-Feb-15 2:03
MA11026-Feb-15 2:03 
AnswerRe: Need help for auto response of a sms Pin
Richard Andrew x6426-Feb-15 9:08
professionalRichard Andrew x6426-Feb-15 9:08 
QuestionNeed various algo asked during interview for dotnet C# Pin
Tridip Bhattacharjee26-Feb-15 0:19
professionalTridip Bhattacharjee26-Feb-15 0:19 
AnswerRe: Need various algo asked during interview for dotnet C# Pin
Pete O'Hanlon26-Feb-15 0:56
mvePete O'Hanlon26-Feb-15 0:56 
GeneralRe: Need various algo asked during interview for dotnet C# Pin
Tridip Bhattacharjee26-Feb-15 2:25
professionalTridip Bhattacharjee26-Feb-15 2:25 
GeneralRe: Need various algo asked during interview for dotnet C# Pin
Richard Givis24-Mar-15 11:03
Richard Givis24-Mar-15 11:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.