CLR behavior about accessing data during garbage collection working

  • Thread starter Thread starter Hyun-jik Bae
  • Start date Start date
H

Hyun-jik Bae

I got a curiosity while using CLR.
How can it be done that accessing object data by CLR application is safe
even while garbage collector is working? Is the GC thread running in
realtime priority for this for example?
Please reply. Thanks in advance.

Hyun-jik Bae
 
The CLR pauses all threads while garbage collecting. Thats why it is a
performance hit to call it yourself and to keep invoking it with short term
memory allocations.

Ciaran O'Donnell
 
Hello Hyun-jik Bae,

Just to add Ciaran's post:
GC pause nothing, it just ask CLR to suspend/resume threads.
It's not just simple suspension, there are some cases how threads are suspended
based on whether threads are in managed code or not

H> I got a curiosity while using CLR.
H> How can it be done that accessing object data by CLR application is
H> safe
H> even while garbage collector is working? Is the GC thread running in
H> realtime priority for this for example?
H> Please reply. Thanks in advance.
H> Hyun-jik Bae
H>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
I always thought that the GC will not collect managed resources when they
are in use and that's exactly what he is saying no? Unmanaged resources
that's a different story that's why we have GC.KeepAlive()

Gabriel Lozano-Morán
 
Hyun-jik Bae said:
I got a curiosity while using CLR.
How can it be done that accessing object data by CLR application is safe
even while garbage collector is working? Is the GC thread running in

It isn't.... the gc moves everything. That's why the GC suspends all
threads in managed code before it starts running.
 
Hello Ben,

A small addition - GC calls functions to do the suspension and the resumption
as a service provided in the CLR.
It's the work of CLR and EE(Execution Engine) to manage this

BV> BV>BV> It isn't.... the gc moves everything. That's why the GC suspends
BV> all threads in managed code before it starts running.
BV>---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Back
Top