When methods are called, do they go on the stack, or an entry pointing to the method go on the stack?
Example
Code:
static void Main()
{
TestMethod();
}
void TestMethod()
{
//do something
}
Stack:
TestMethod() ---------> //do something executable code
Main()
-or-
//do something code
TestMethod()
Main()
Do methods belonging to objects go on the Heap with the object, or do they go on the stack?
Example
Code
static class Program
{
static void Main()
{
TestClass Testobj = new TestClass();
}
}
class TestClass
{
TestClass()
{
TestClassesMethod();
}
TestClassesMethod()
{
// do something
}
}
Stack and Heap:
Stack /////////////// Heap
Testobj ---------> TestClass
Main() /////////////TestClassesMethod()
-or-
Stack //////////////// Heap
TestClassesMethod()
Testobj ------------> TestClass
Main()
In C# Winforms apps specifically, since Main() goes on the stack (as most other programming languages), does Form1() also start off on the stack (Application.Run(newForm1())
-or- is it a new object and generated on the heap?
Stack ///////////////////////Heap
Form1 Reference --------> Form1
Main()
-or-
Stack ////////////////////////Heap
InitializeComponent()
Form1()
Main()
Lastly, is any executable code actually stored on the stack and heap, or just data and placeholders referencing executable code memory locations?
Thank you
PS - I had to put ////'s for blank space in my stack and heap examples, it kept reformatting my post.
Example
Code:
static void Main()
{
TestMethod();
}
void TestMethod()
{
//do something
}
Stack:
TestMethod() ---------> //do something executable code
Main()
-or-
//do something code
TestMethod()
Main()
Do methods belonging to objects go on the Heap with the object, or do they go on the stack?
Example
Code
static class Program
{
static void Main()
{
TestClass Testobj = new TestClass();
}
}
class TestClass
{
TestClass()
{
TestClassesMethod();
}
TestClassesMethod()
{
// do something
}
}
Stack and Heap:
Stack /////////////// Heap
Testobj ---------> TestClass
Main() /////////////TestClassesMethod()
-or-
Stack //////////////// Heap
TestClassesMethod()
Testobj ------------> TestClass
Main()
In C# Winforms apps specifically, since Main() goes on the stack (as most other programming languages), does Form1() also start off on the stack (Application.Run(newForm1())
Stack ///////////////////////Heap
Form1 Reference --------> Form1
Main()
-or-
Stack ////////////////////////Heap
InitializeComponent()
Form1()
Main()
Lastly, is any executable code actually stored on the stack and heap, or just data and placeholders referencing executable code memory locations?
Thank you
PS - I had to put ////'s for blank space in my stack and heap examples, it kept reformatting my post.