470,855 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Don't understand keepalive...

Hi!
I've got a problem with the GC.keepalive function,
as used in the examples at
http://msdn2.microsoft.com/en-US/lib...keepalive.aspx
..
There they have a class "Example", construct it and call a method,
during which it may get collected.
Why would it get collected, before the last method call ends?
Is this a bug on the GC or is there a resson for it?

Lots of greetings!
Volker
--
For email replies, please substitute the obvious.
May 22 '06 #1
2 1583
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.

--
"Volker Hetzer" <fi****************@ieee.org> schrieb im Newsbeitrag
news:e4**********@nntp.fujitsu-siemens.com...
Hi!
I've got a problem with the GC.keepalive function,
as used in the examples at
http://msdn2.microsoft.com/en-US/lib...keepalive.aspx
.
There they have a class "Example", construct it and call a method,
during which it may get collected.
Why would it get collected, before the last method call ends?
Is this a bug on the GC or is there a resson for it?

Lots of greetings!
Volker
--
For email replies, please substitute the obvious.

May 22 '06 #2
cody schrieb:
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/lib...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
--
For email replies, please substitute the obvious.
May 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by unni | last post: by
1 post views Thread by Cliff Harris | last post: by
reply views Thread by Kevin | last post: by
4 posts views Thread by Kalpesh Modha | last post: by
reply views Thread by Ziphyre | last post: by
reply views Thread by Greg | last post: by
1 post views Thread by okaminer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.