Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
AI

The AI Prompt That Hunts Down a Leaked Event Subscription

- 30.11.26 - ErcanOPAK

🤖 The AI Prompt That Hunts Down a Leaked Event Subscription

A memory leak from an object that subscribed to an event and never unsubscribed is one of the hardest bugs to spot by reading code top to bottom, because the subscribing line and the missing unsubscribe live in two completely different methods, often two different classes, and nothing about either one looks wrong in isolation.

🔎 The Problem

Prompt:

"Here is [paste a class and the classes it interacts with]. For every
+= event subscription in this code, tell me: (1) where the matching
-= unsubscribe is, if any, (2) whether the subscribing object's
lifetime is shorter than the event source's lifetime, and (3) if it
is, show me exactly where to add the unsubscribe call and whether
IDisposable is the right place to put it."

✅ Fix: Why This Prompt Works

  • It forces a pairing check (subscribe vs. unsubscribe) instead of asking the model to ‘find the memory leak’, which is too vague a target for it to search for reliably.
  • Asking explicitly about relative object lifetimes is the actual root cause test for this class of bug — a short-lived subscriber tied to a long-lived publisher is the signature pattern every time.
  • Requesting a specific fix location (and whether IDisposable fits) turns the answer into something you can act on immediately, rather than a general explanation of event leaks.

💡 Good to Know

  • This works especially well on WPF/WinForms view models and on any publish-subscribe service registered as a singleton, since those are exactly where lifetime mismatches tend to hide.

The bug isn’t in the line that subscribes — it’s in the line that was supposed to exist somewhere else and doesn’t.

— AI Power User

Related posts:

AI Prompt: Language-to-Language Logic Translation

AI Prompt: Language-to-Language Logic Translation

The AI Prompt That Reviews a CI/CD Pipeline YAML File for Security and Secret-Exposure Risks Before ...

The AI Prompt That Reviews a CI/CD Pipeline YAML File for Security and Secret-Exposure Risks Before ...

The Code-Review Prompt That Catches Bugs Human Reviewers Miss

The Code-Review Prompt That Catches Bugs Human Reviewers Miss

Views: 7
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

JavaScript: Fix a Generator Function Leaking Across Iterations
HTML5: Fix a Picture Element Serving the Wrong Art Direction Source

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com