Ich habe eine mittelgroße Anwendung mit einer Tabelle und eine Funktion der Tabelle ist die Möglichkeit, auf eine Schaltfläche zu klicken, die eine Ansicht dieser Zeile in Form eines Muddialogs öffnet. Der Dialog lädt Daten aus einer API in und zeigt es an. Vor allem lädt es auch Audio ein, das dann in Base64 konvertiert wird, damit der eingebettete HTML -Audio -Player funktioniert. Dies wäre jedoch kein Problem, wenn Muddialog alle seine Ressourcen in der Nähe ordnungsgemäß entsorgt hätte. Was passiert, ist, dass jedes Mal, wenn ein Dialog geöffnet wird, dem Dialog zugewiesen zu sein scheint, und nach Schluss nicht wie in meinem Speicherhaufen zu sehen ist: Speicherhaufen.
Code: Select all
@inject IDialogService DialogService
private readonly DialogOptions _dialogOptions = new() { MaxWidth = MaxWidth.Medium, FullWidth = true, CloseButton = true, CloseOnEscapeKey = true, NoHeader = false };
private async Task OpenDialogViewAsync(int id, string name)
{
JsonDocument text = await GetText(textId);
var parameters = new DialogParameters
{
{ "name", name},
{ "jsonContent", text},
{ "id", transcriptionId}
};
var completeTitle = $"File: {name}";
var dialog = await DialogService.ShowAsync(completeTitle, parameters, _dialogOptions);
var result = await dialog.Result;
}
< /code>
TextViewDialog.razor
@implements IDisposable
protected override async Task OnInitializedAsync()
{
_loading = true;
await PerformSearch();
_loading = false;
await LoadAudioUrl();
StateHasChanged();
}
private async Task LoadAudioUrl()
{
try
{
audioBytes = await getAudio(id);
if (audioBytes != null && audioBytes.Length > 0)
{
audioUrl = $"data:audio/mpeg;base64,{Convert.ToBase64String(audioBytes)}";
Logger.LogInformation("Audio URL set successfully.");
}
else
{
Logger.LogWarning("Audio file is empty or null.");
}
}
catch (Exception ex)
{
Logger.LogError(ex, "Error loading audio URL");
Snackbar.Add($"Error loading audio URL: {ex.Message}", MudBlazor.Severity.Error);
}
StateHasChanged();
}
private void Close()
{
Dispose();
MudDialog.Close(DialogResult.Ok(true));
}
< /code>
I have tried implementing IDisposable and clearing the variables defined in that dialog:
public void Dispose()
{
JSRuntime.InvokeVoidAsync("disposeAudioPlayer");
JsonContent = null;
TextContent = null;
Array.Clear(audioBytes, 0, audioBytes.Length);
}
< /code>
But that had no effect. I read that MudBlazor calls the Dispose() method once the dialog is closed but I don't seem to be able to understand what the root cause of the issue is or if I am setting something up wrong.
Ich habe eine mittelgroße Anwendung mit einer Tabelle und eine Funktion der Tabelle ist die Möglichkeit, auf eine Schaltfläche zu klicken, die eine Ansicht dieser Zeile in Form eines Muddialogs öffnet. Der Dialog lädt Daten aus einer API in und zeigt es an. Vor allem lädt es auch Audio ein, das dann in Base64 konvertiert wird, damit der eingebettete HTML -Audio -Player funktioniert. Dies wäre jedoch kein Problem, wenn Muddialog alle seine Ressourcen in der Nähe ordnungsgemäß entsorgt hätte. Was passiert, ist, dass jedes Mal, wenn ein Dialog geöffnet wird, dem Dialog zugewiesen zu sein scheint, und nach Schluss nicht wie in meinem Speicherhaufen zu sehen ist: Speicherhaufen.[code]Parent.razor[/code]
[code]@inject IDialogService DialogService
private readonly DialogOptions _dialogOptions = new() { MaxWidth = MaxWidth.Medium, FullWidth = true, CloseButton = true, CloseOnEscapeKey = true, NoHeader = false };
private async Task OpenDialogViewAsync(int id, string name)
{
JsonDocument text = await GetText(textId);
var parameters = new DialogParameters
{
{ "name", name},
{ "jsonContent", text},
{ "id", transcriptionId}
};
var completeTitle = $"File: {name}";
var dialog = await DialogService.ShowAsync(completeTitle, parameters, _dialogOptions);
var result = await dialog.Result;
}
< /code>
TextViewDialog.razor[/code]
@implements IDisposable
protected override async Task OnInitializedAsync()
{
_loading = true;
await PerformSearch();
_loading = false;
await LoadAudioUrl();
StateHasChanged();
}
private async Task LoadAudioUrl()
{
try
{
audioBytes = await getAudio(id);
if (audioBytes != null && audioBytes.Length > 0)
{
audioUrl = $"data:audio/mpeg;base64,{Convert.ToBase64String(audioBytes)}";
Logger.LogInformation("Audio URL set successfully.");
}
else
{
Logger.LogWarning("Audio file is empty or null.");
}
}
catch (Exception ex)
{
Logger.LogError(ex, "Error loading audio URL");
Snackbar.Add($"Error loading audio URL: {ex.Message}", MudBlazor.Severity.Error);
}
StateHasChanged();
}
private void Close()
{
Dispose();
MudDialog.Close(DialogResult.Ok(true));
}
< /code>
I have tried implementing IDisposable and clearing the variables defined in that dialog:
public void Dispose()
{
JSRuntime.InvokeVoidAsync("disposeAudioPlayer");
JsonContent = null;
TextContent = null;
Array.Clear(audioBytes, 0, audioBytes.Length);
}
< /code>
But that had no effect. I read that MudBlazor calls the Dispose() method once the dialog is closed but I don't seem to be able to understand what the root cause of the issue is or if I am setting something up wrong.