Alex Rivera | Logout

How does GC.AddMemoryPressure() know which object to add memory pressure to?

Asked 2012-01-25T14:58:07.347
8

I recently had need to use GC.AddMemoryPressure and it struck me as strange that it doesn't accept the object to add memory pressure to as an argument. I assume because it's so closely tied to the runtime, there is some mechanism by which the this pointer gets passed to the method. My question is threefold:

  1. How does the this pointer get passed to the method?
  2. I notice no exception is thrown when calling it from a static method. What happens in this case?
  3. Why do other GC methods such as GC.SupressFinalize and GC.ReRegisterForFinalize take an object argument where this method doesn't need one?
Edit
Report

1 Answer

1

AddMemoryPressure kicks the garbage collector into life sooner than it would do normally. That's all. Suppress and RegisterForFinialise call or not specific code for that type when an instance gets collected and it's finaliser needs to be run...

Suggest you read up on the garbage collector mate, you might find that you didn't need to call IncreaseMemoryPressure, or almost just as likely calling it will cause a deteriation in performance.

answered 2012-01-25T15:06:53.770

Your Answer