Replies: 5 comments 5 replies
-
GC.Collect() |
Beta Was this translation helpful? Give feedback.
-
What value would it have to hint to the GC (if you could somehow)? It will collect garbage when it thinks it needs to in order to satisfy an allocation request. |
Beta Was this translation helpful? Give feedback.
-
@danmoseley. This for sure no common scenario. I was only thinking about my current scenario where I'm working with many GB/TB of data where I'm allocating a lot in the LOH. Almost 90% of the data are in the LOH. The amount of data I need to allocate during one run is dependent on the input data which range from 5GB to 120GB). During processing multiple intermediate datasets of the same size are allocated (50-100, so for the extreme case it could happend that I allocate 120TB during one run), not all at once but during the whole processing chain. Which means the required amount of memory goes way beyond what is available in the system memory (max. 256GB but it's able to scale) so I crceated some sort of memory mapped files without using them for many reasons:
Due to this problems I need to manage things myself and created my own memory mapped files (although I find this stupid and would prefer using memory mapped files - but as shown above a few links are missing, especially the dirty bit and the information when paging is running). The reason why I'm asking if the GC can be given some additional information (in LOH only) if it would help to coordinate the cleanup for the LOH better. Still, of course the GC has to check for references to the data but if the GC would know better it could prioritize the memory that has been marked with this "special" advise method. I also thought about having some sort of ArrayPool, but I don't know the size of the data in advance and there are many different ranges of data sizes (from 32x32 to 4096x4096) and additionally the ArrayPools need to cooperate and lose memory in favor of other pools that currently need memory pressure is higher than on others. Thats why I have some sort of master control unit that coordinates the memory among the pools . Its not that I urgently need such an Advise method and of course its a very uniqe scenario, it's just a thought experiment if it could potentially improve GC performance in LOH cleanups. Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
The idea is a good idea, but such a hint would not be actionable for the GC. In order to collect memory, the GC has to check whether the memory is reachable from anywhere. This means that it has to scan all the stacks, all pointers from there, all pointers from there, etc. until it has found all reachable objects. That's the expensive part of GC. Even if the GC got the hint to collect a single object, it would have to determine its reachability - and for that it has to scan the "world". Now that the GC scanned the world, it might have detected a lot of unreachable objects. It makes sense to collect all these objects in one swoop. In short: Getting a hint for a single object doesn't improve the situation over |
Beta Was this translation helpful? Give feedback.
-
Is |
Beta Was this translation helpful? Give feedback.
-
Just an idea that came up lately. Does it make sense or is it even possible to advise the GC to cleanup object in the LOH? The idea arose from another question regarding the need for enforcing a LOH compaction.
My question is if you know that you need to cleanup an object, does it help to assist the GC to prioritize these objects?
Beta Was this translation helpful? Give feedback.
All reactions