Skip to content

Commit 175a748

Browse files
committed
improved memory management
1 parent eb1fd4c commit 175a748

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Web/Pages/Mailbox.razor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ partial class Mailbox : IRecipient<MailReceivedMessage>, IDisposable
2626

2727
protected MailModel CurrentMail { get; private set; }
2828

29-
protected override void OnParametersSet()
29+
protected override async Task OnInitializedAsync()
3030
{
31-
this.MailboxSessionService.MailReceived += this.MailboxSessionService_MailReceived;
32-
}
31+
await base.OnInitializedAsync();
3332

34-
protected override async Task OnAfterRenderAsync(bool firstRender)
35-
{
33+
this.MailboxSessionService.MailReceived += this.MailboxSessionService_MailReceived;
3634
await this.JsRuntime.InvokeVoidAsync("window.TempMailServer.InitializeAutoSelect");
35+
this.Messenger.Register(this);
3736
}
3837

3938
private void MailboxSessionService_MailReceived(object sender, EventArgs e)
@@ -78,6 +77,7 @@ public void Receive(MailReceivedMessage message)
7877

7978
public void Dispose()
8079
{
80+
this.Messenger.UnregisterAll(this);
8181
this.MailboxSessionService.MailReceived -= this.MailboxSessionService_MailReceived;
8282
}
8383
}

Web/Services/MailboxSessionService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Lyralabs.TempMailServer.Web.Services
77
{
8-
public class MailboxSessionService : IRecipient<MailReceivedMessage>
8+
public class MailboxSessionService : IRecipient<MailReceivedMessage>, IDisposable
99
{
1010
public event EventHandler MailReceived;
1111

@@ -115,5 +115,11 @@ internal async Task<MailModel> GetMailByIdAsync(int mailId)
115115
var mail = await this.mailboxService.GetDecryptedMailById(this.userState.CurrentMailbox, mailId, this.userState.Secret.Value.PrivateKey);
116116
return mail;
117117
}
118+
119+
public void Dispose()
120+
{
121+
this.messenger.UnregisterAll(this);
122+
this.Mails.Clear();
123+
}
118124
}
119125
}

0 commit comments

Comments
 (0)