Home / Forums / Fast Object Pooling implementation in C# with ConcurrentBag / Stack [Discussion #3]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

Fast Object Pooling implementation in C# with ConcurrentBag / Stack [Discussion #3]

UI_Wizard
ImGui Widget Dev
MEMBER
Rep: 72
Join Date: Feb 2021
Posts: 6
Thanks: 95
6y ago · Jan 10, 2020 5:12 PM
#1
Here is a generic lock-free ObjectPool<T> in C# for reusing expensive game entities and memory streams without GC pressure.
UI_Wizard · ImGui Widget Dev
Writing complex custom ImGui widgets: color pickers, curve e...
The following users thanked UI_Wizard for this post:
StackUnwinder
Debugging & Profiling
MEMBER
Rep: 145
Join Date: Jun 2025
Posts: 6
Thanks: 16
6y ago · Jan 10, 2020 8:18 PM
#2
Pre-warming the pool on startup with 100 instances completely eliminated GC collections during active combat gameplay!
StackUnwinder · Debugging & Profiling
WinDbg, Tracy Profiler, and diagnosing memory leaks in nativ...
SourceGenDev
C# Tooling
MEMBER
Rep: 158
Join Date: Jan 2020
Posts: 8
Thanks: 79
6y ago · Jan 11, 2020 12:18 AM
#3
Make sure to reset the object state in Return() so previous data does not leak into the next rented instance.
SourceGenDev · C# Tooling
Metaprogramming with C# 9+ Source Generators and Roslyn Anal...