C# Winforms GUI : Stack and Heap question
-
Does Application.Run((new Form1()); in Program.cs load on the Stack or Heap? I am asking to see if all methods inside the Form1 code are methods that go on the Stack or Heap. Also, if I create a new Form object from Form1 - does it load on the Stack or Heap? What about methods processed inside of new objects. Example: public partial class Form1 : Form { public Form1() { Doofus d = new Doofus(); } } public class Doofus { Doofus() { createsomething(); } void createsomething() { string a = "whiskey"; } } In this, does d's createsomething() method go on the stack or the heap? I have read several articles on this, and I have "googled it myself". I'd just like a straightforward answer if anyone knows. Thank you
-
Does Application.Run((new Form1()); in Program.cs load on the Stack or Heap? I am asking to see if all methods inside the Form1 code are methods that go on the Stack or Heap. Also, if I create a new Form object from Form1 - does it load on the Stack or Heap? What about methods processed inside of new objects. Example: public partial class Form1 : Form { public Form1() { Doofus d = new Doofus(); } } public class Doofus { Doofus() { createsomething(); } void createsomething() { string a = "whiskey"; } } In this, does d's createsomething() method go on the stack or the heap? I have read several articles on this, and I have "googled it myself". I'd just like a straightforward answer if anyone knows. Thank you
Methods do neither, they are loaded into the code section of the application's memory on startup. Objects are generally created on the heap and values and temporary variables on the stack.
Form1
will be created on the heap, as will (generally) all its components.Use the best guess
-
Does Application.Run((new Form1()); in Program.cs load on the Stack or Heap? I am asking to see if all methods inside the Form1 code are methods that go on the Stack or Heap. Also, if I create a new Form object from Form1 - does it load on the Stack or Heap? What about methods processed inside of new objects. Example: public partial class Form1 : Form { public Form1() { Doofus d = new Doofus(); } } public class Doofus { Doofus() { createsomething(); } void createsomething() { string a = "whiskey"; } } In this, does d's createsomething() method go on the stack or the heap? I have read several articles on this, and I have "googled it myself". I'd just like a straightforward answer if anyone knows. Thank you
-
Looking at some of your other questions, I would strongly recommend .NET Book Zero[^].
Use the best guess
Thanks man.
-
Does Application.Run((new Form1()); in Program.cs load on the Stack or Heap? I am asking to see if all methods inside the Form1 code are methods that go on the Stack or Heap. Also, if I create a new Form object from Form1 - does it load on the Stack or Heap? What about methods processed inside of new objects. Example: public partial class Form1 : Form { public Form1() { Doofus d = new Doofus(); } } public class Doofus { Doofus() { createsomething(); } void createsomething() { string a = "whiskey"; } } In this, does d's createsomething() method go on the stack or the heap? I have read several articles on this, and I have "googled it myself". I'd just like a straightforward answer if anyone knows. Thank you
Objects are created on heap; and Application.Run is creating the object Form1 as new Form1(); so it will be created on heap. As, per my understanding, createsomething() will also go on heap as it is part of an object. But better look for memory allocation in .Net and you will have a clear idea about what goes on stack and what goes on heap.