RxJS Subscription Leak Detector
A VS Code extension that helps you identify potential memory leaks caused by unsubscribed RxJS observables in Angular applications.
Features
- Scans your entire Angular codebase for RxJS subscriptions
- Detects components that subscribe to observables but may not properly unsubscribe
- Provides a detailed report of potential leak locations
- Allows you to quickly navigate to problem areas
- Checks for proper implementation of
OnDestroy lifecycle hook
Usage
- Open your Angular project in VS Code
- Open the Command Palette (
Ctrl+Shift+P or Cmd+Shift+P on macOS)
- Run the command:
Detect RxJS Subscription Leaks
- View the results in the webview panel that appears
- Click on file links to navigate directly to potential leak locations
How It Works
The extension analyzes your TypeScript files to find:
- Calls to
.subscribe() methods
- Variables of type
Subscription
- Classes that implement
OnDestroy
ngOnDestroy method implementations that call unsubscribe()
It cross-references this information to identify subscriptions that might not be properly cleaned up.
Extension Settings
No configuration required.
Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions view (
Ctrl+Shift+X or Cmd+Shift+X on macOS)
- Search for "RxJS Subscription Leak Detector"
- Click Install
From VSIX File
- Download the
.vsix file
- Open VS Code
- Go to Extensions view
- Click "..." (More Actions) and select "Install from VSIX..."
- Choose the downloaded file
Build From Source
git clone https://github.com/yourusername/rxjs-subscription-detector.git
cd rxjs-subscription-detector
npm install
npm run compile
Best Practices for Avoiding Subscription Leaks
- Always implement
OnDestroy and unsubscribe in ngOnDestroy
- Use the
takeUntil pattern with a destroy subject
- Use the async pipe in templates where possible
- Store subscriptions in a collection and unsubscribe from all at once
- Use finite observables like
take(1) for one-time operations
Known Limitations
- False positives might occur for subscriptions that complete naturally
- May not detect subscriptions stored in arrays or complex data structures
- Limited analysis of dynamic subscription patterns
- Doesn't analyze template files for async pipe usage
License
MIT
| |