3 ms·
You can, kind of. It's not pretty though. Unless you have a remarkably specific need, disabling GC is almost always the wrong path. The "correct" way is to ma
by calamari4065 3y ago
You can, kind of. It's not pretty though.
Unless you have a remarkably specific need, disabling GC is almost always the wrong path.
The "correct" way is to manipulate GC. You can suspend, manually start a GC run, pin memory, exempt an object from GC, and a few other things I've never played with.
AFAIK the only thing you can't do is immediately deallocate an object. But honestly I can't come up with a situation where an object must be deallocated immediately. Depending on your exact use case, there's ways around that if you really, really need to.
In general, the GC will almost always perform better than any manual manipulation you'd do to it. The main "acceptable" use is suspending GC inside very hot code and deferring the collection until your program is less busy. Like suspending GC while processing one frame in a game, and manually running GC in the space between frames. Even then, this is still discouraged.
Out of curiosity, what's your use case here? I really can't think of any situation that doesn't have a better solution.