Is there any way to be notified that there will be a garbage pickup?

Asked

Viewed 83 times

6

I’m studying about the Garbage Collector do . NET and wanted to know if there are any events that I can sign and be aware whenever a collection will be made.

1 answer

7


Event even does not have, this would be little useful since at the time you need to make the collection nothing else can be done.

What you can do is be notified before an allocation is made, it is not something simple and you need to set up your own event system, preferably in another thread. This can be seen in GC.RegisterForFullGCNotification.

This way it is possible to know when a large allocation will be made and possibly generate a collection and then decide what to do. This is useful for testing, but not interesting in production because it has overhead. Has application notifying a load not to send more requests to it until the collection is finished, so another instance or another server can continue to meet the demand without pauses. I see no use in anything other than that.

In the class documentation GC has several very advanced things about using GC. GC’s configurability and monitoring. NET is not the best, but it has some good things and is getting better. Apart from this it is possible to use tools that help diagnose memory issues.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.