Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Winforms GUI : Stack and Heap question

C# Winforms GUI : Stack and Heap question

Scheduled Pinned Locked Moved C#
csharpquestionwinformsdata-structurestutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DSLoginYea
    wrote on last edited by
    #1

    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

    L S 3 Replies Last reply
    0
    • D DSLoginYea

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D DSLoginYea

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Looking at some of your other questions, I would strongly recommend .NET Book Zero[^].

        Use the best guess

        D 1 Reply Last reply
        0
        • L Lost User

          Looking at some of your other questions, I would strongly recommend .NET Book Zero[^].

          Use the best guess

          D Offline
          D Offline
          DSLoginYea
          wrote on last edited by
          #4

          Thanks man.

          1 Reply Last reply
          0
          • D DSLoginYea

            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

            S Offline
            S Offline
            SaqibRasheed
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups