variable memory to release for heap or stack
-
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
-
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
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.”
-
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.”
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?
-
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?
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.”
-
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.”
Thank You
-
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.”
I know the managed code and unmanaged code. But can u tell me any link that tell about the managed object and unmanaged objects.
-
I know the managed code and unmanaged code. But can u tell me any link that tell about the managed object and unmanaged objects.
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.”