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. Visual Basic
  4. variable memory to release for heap or stack

variable memory to release for heap or stack

Scheduled Pinned Locked Moved Visual Basic
data-structuresperformancequestionannouncement
7 Posts 2 Posters 1 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.
  • P Offline
    P Offline
    Pankaj Garg
    wrote on last edited by
    #1

    Hi, Should i take care of both the variables which are consuming the memory on heap/stack, while releasing the memory in finally? Or just heap variables are enough to be released? dim d as integer=0 Dim f As DataGridView=nothing try d = 10 f=new datagridview catch(byval ex as exception) finally d=nothing f=nothig end try

    H 1 Reply Last reply
    0
    • P Pankaj Garg

      Hi, Should i take care of both the variables which are consuming the memory on heap/stack, while releasing the memory in finally? Or just heap variables are enough to be released? dim d as integer=0 Dim f As DataGridView=nothing try d = 10 f=new datagridview catch(byval ex as exception) finally d=nothing f=nothig end try

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Both of the members will be released and disposed when their references go out of scope. However from the code that you have shown there would be no harm in doing as you have done.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      P 1 Reply Last reply
      0
      • H Henry Minute

        Both of the members will be released and disposed when their references go out of scope. However from the code that you have shown there would be no harm in doing as you have done.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        P Offline
        P Offline
        Pankaj Garg
        wrote on last edited by
        #3

        Henry Minute wrote:

        Both of the members will be released and disposed when their references go out of scope

        Then why should i dispose the objects in finally?

        H 1 Reply Last reply
        0
        • P Pankaj Garg

          Henry Minute wrote:

          Both of the members will be released and disposed when their references go out of scope

          Then why should i dispose the objects in finally?

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          It depends on what the objects are. For example, it is recommended that Graphics instances, Pens, Brushes etc. are disposed as soon as they are no longer needed, becuase you cannot know how long it will take for the Garbage Collector to do its work. In addition any unmanaged objects should be disposed in this way. It does no harm to manually dispose objects, it is just that it is not always necessary.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          P 2 Replies Last reply
          0
          • H Henry Minute

            It depends on what the objects are. For example, it is recommended that Graphics instances, Pens, Brushes etc. are disposed as soon as they are no longer needed, becuase you cannot know how long it will take for the Garbage Collector to do its work. In addition any unmanaged objects should be disposed in this way. It does no harm to manually dispose objects, it is just that it is not always necessary.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            P Offline
            P Offline
            Pankaj Garg
            wrote on last edited by
            #5

            Thank You

            1 Reply Last reply
            0
            • H Henry Minute

              It depends on what the objects are. For example, it is recommended that Graphics instances, Pens, Brushes etc. are disposed as soon as they are no longer needed, becuase you cannot know how long it will take for the Garbage Collector to do its work. In addition any unmanaged objects should be disposed in this way. It does no harm to manually dispose objects, it is just that it is not always necessary.

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              P Offline
              P Offline
              Pankaj Garg
              wrote on last edited by
              #6

              I know the managed code and unmanaged code. But can u tell me any link that tell about the managed object and unmanaged objects.

              H 1 Reply Last reply
              0
              • P Pankaj Garg

                I know the managed code and unmanaged code. But can u tell me any link that tell about the managed object and unmanaged objects.

                H Offline
                H Offline
                Henry Minute
                wrote on last edited by
                #7

                Try this[^] for some info about unmanaged objects (resources). For information about both, try googling managed v unmanaged objects or managed and unmanaged objects. There are so many hits that it is difficult to pick one for you. Have a look for yourself.

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                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