Don't understand keepalive...

  • Thread starter Thread starter Volker Hetzer
  • Start date Start date
if a object is passed into a native method the GC cannot track it. therefore
you have to use keepalive to make sure it is not collected until the method
returns.
 
cody said:
if a object is passed into a native method the GC cannot track it. therefore
you have to use keepalive to make sure it is not collected until the method
returns.
Yes, I have no problem accepting that.
However, the way I read the documentation (hopefully wrongly) there's some
way the garbage collector can try to reclaim an object while it is involved
in an actual method call and no unmanaged code is involved in any way.

The example in http://msdn2.microsoft.com/en-US/library/system.gc.keepalive.aspx
appears to be indicating that there is a nonzero possibility that an object
(ex in this case) gets collected between those two lines of code
Dim ex As New Example()
Dim res As Byte() = ex.Hash
..

Lots of Greetings!
Volker
 
Back
Top