Hi All
What is the use of garbage control?, when we go for this? i need answer with small example, thanks in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 13, 2014, 7:32 AM
The output is:
After MyMethod() ends, there are no longer any references to the MyClass object and so it is marked for garbage collection. However, as there is no pressure to allocate new objects, its destructor is not run and its memory reclaimed until after a key is pressed.
Normally, it doesn't matter much when the GC runs. However, in some cases, this indeterminate behavior can be a problem and in those cases you can trigger an immediate garbage collection by calling GC.Collect().
So, if you change the Main method to this:
the output now is :
showing that the object has now been de-allocated before the key is pressed.
Joginder BangerPosted Nov 13, 2014, 4:37 AM
I assume you are familiar with c and C++ language. Suppose we are not assign any number
int i; By default value assign like '213245' In c language
int i; By default value assign 0. Not a garbage value.
In c language developer (programmer) worry about the memory because in c language have no garbage control.
In C# language no worry about the memory.