Mike Bruno
897 posts

Mike Bruno
@PkiMike
One of the developers of PKI Spotlight, a revolutionary PKI monitoring and alerting tool. Cybersecurity professional.



𝟱𝟬% 𝗼𝗳 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀 𝗳𝗮𝗰𝗲𝗱 𝗺𝗲𝗺𝗼𝗿𝘆 𝗹𝗲𝗮𝗸𝘀 𝘄𝗶𝘁𝗵 𝗘𝗙 𝗖𝗼𝗿𝗲 They're making the same mistake 👇 ❌ Improper handling of DbContext lifetimes. Many devs simply register DbContext as scoped and call it a day. ▶️ But reality is often more complex. DbContext isn't thread-safe — sharing it across threads will cause exceptions. It's lightweight and meant to be short-lived, instantiated frequently, and disposed properly. ❌ Improper handling leads to growing memory usage and eventual leaks. Thankfully, EF Core provides solutions to handle complex scenarios: ↳ 𝗜𝗗𝗯𝗖𝗼𝗻𝘁𝗲𝘅𝘁𝗙𝗮𝗰𝘁𝗼𝗿𝘆 Allows safe, on-demand creation of DbContext instances — perfect for background tasks, multi-threading and desktop applications. ↳ 𝗗𝗯𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗣𝗼𝗼𝗹𝗶𝗻𝗴 Reuses pre-configured DbContext instances to minimize performance overhead. Pooling resets contexts after use, significantly cutting down memory and CPU waste. ↳ 𝗣𝗼𝗼𝗹𝗲𝗱 𝗗𝗯𝗖𝗼𝗻𝘁𝗲𝘅𝘁𝗙𝗮𝗰𝘁𝗼𝗿𝘆 Want the best of both worlds? Combine DbContextFactory with Pooling — Pooled DbContextFactory. You get on-demand contexts that are efficiently reused, optimizing your app's performance. ✅ Always dispose contexts promptly—either with using statements or returning them to the pool. ✅ Never share DbContext across threads. Proper lifecycle management boosts application stability, responsiveness, and scalability. Understanding these nuances can eliminate those sneaky memory leaks that plague many EF Core projects. Here are 10 more mistakes developers make in EF Core: ↳ antondevtips.com/blog/top-10-mi… —— ♻️ Repost to help others avoid memory leaks in EF Core ➕ Follow me ( @AntonMartyniuk ) to improve your .NET Skills













is M1 still worth in 2025 ?












