.net - Understanding gcroot -


i have been reading article understand gcroot template. understand

gcroot provides handles garbage collected heap

and

the handles not garbage collected.

what don't understand following:

when clr object moves garbage-collected heap, handle return new address of object. variable not have pinned before assigned gcroot template.

does mean clr object deleted garbage collector if there gcroot handle referencing object?

what "new address" refers to? , mean "variable not have pinned before assigned gcroot template"?

garbage collection doesn't remove unreferenced objects, moves around objects still referenced, e.g. defragment free memory pool. when article talks objects moving in clr heap, it's saying "when garbage collection moves still-referenced object, gcroot handle automatically updated still point clr object."

you can prevent gc moving objects around using pin_ptr keyword, so:

object ^obj = gcnew <something>; pin_ptr pinned = obj;  /* obj won't move due gc long pinned in scope. */ /* interop-y here, pass native code in dll, etc. */ 

see this article more information pinning.

observation: article may have typo. if had said "within garbage-collected heap" instead of "with garbage-collected heap", have improved understanding? way it's phrased in article makes sound earth move under feet whenever gc cleaned house.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -