how unmanaged code is garbage collected

Posted by Nkkppp under C# on 11/7/2012 | Points: 10 | Views : 3513 | Status : [Member] | Replies : 2
Hi,

The code which runs directly under the control of code manager in CLR is called managed code. So the Garbage collector will take care of memory deallocation,providing security etc.

Then what about the unmanaged code like if pointers are used using the keyword Unsafe within the code. How the memory is deallocated for the same, because all the unmanaged code is executed under the control of operating system.

Thanks,
Prathap.




Responses

Posted by: Seng2hs on: 11/8/2012 [Member] Starter | Points: 25

Up
0
Down
You need to cleanup the memory by your self. Ypu want to dispose the unmanaged code in your code.

Using IDisposable interface use can do it. Implement IDisposable interface and write your cleanup code in the below method

private void Dispose(bool disposing)
{
if (!disposed && disposing)
{
//your clean code
disposed = true;
}
}


Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 11/8/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sengh,

Thanks for the response. So unmanaged code memory will be disposed by the CPU?.Is this what you are trying to explain.

Regards,
Prathap.

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response