Skip to content

Commit 69b690b

Browse files
committed
Create GitHub issue for fixing memory leak in RouteViewHost
1 parent 8d30e71 commit 69b690b

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

  • repos/idotta/SimpleRouter/issues

repos/idotta/SimpleRouter/issues/1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# [CRITICAL] Fix memory leak in RouteViewHost - Event handler not unsubscribed
2+
3+
## Priority: CRITICAL 🔴
4+
5+
## Location
6+
`SimpleRouter.Avalonia/RouteViewHost.cs:30`
7+
8+
## Issue Description
9+
Event handler is subscribed to the router's `OnRouteChanged` event but never unsubscribed when the Router changes or the control is disposed. This causes a memory leak in applications with dynamic router changes.
10+
11+
**Current Code:**
12+
```csharp
13+
router.OnRouteChanged += Router_OnRouteChanged;
14+
```
15+
16+
## Impact
17+
- Memory leaks in applications with dynamic router changes
18+
- Event handlers remain in memory even after the control is disposed
19+
- Can lead to increased memory consumption over time
20+
21+
## Fix Required
22+
23+
```csharp
24+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
25+
{
26+
base.OnPropertyChanged(change);
27+
switch (change.Property.Name)
28+
{
29+
case nameof(Router):
30+
// Unsubscribe from old router
31+
if (change.OldValue is IRouter oldRouter)
32+
{
33+
oldRouter.OnRouteChanged -= Router_OnRouteChanged;
34+
}
35+
36+
// Subscribe to new router
37+
if (change.NewValue is IRouter newRouter)
38+
{
39+
newRouter.OnRouteChanged += Router_OnRouteChanged;
40+
NavigateToRoute(newRouter.Current);
41+
}
42+
break;
43+
}
44+
}
45+
```
46+
47+
## Tasks
48+
- [ ] Implement unsubscription logic for old router events
49+
- [ ] Add proper disposal pattern
50+
- [ ] Add unit test to verify event handler cleanup
51+
- [ ] Add memory leak test
52+
53+
## Phase
54+
**Phase 1: Critical Fixes** (Required for Production)
55+
56+
## References
57+
- Production Readiness Analysis: Line 95-129

0 commit comments

Comments
 (0)