0

メッセージがある場合にユーザーに警告するウィンドウがあります(以下のコード)。
毎回timer1.Elapsed、アプリのメモリが 1 MB 以上増加します。アラートが 10 回発生すると、15 MB を超えます。その後、さらにアラートがある場合、使用済みメモリはほとんど上昇しません。

単純なウィンドウの 15 MB のメモリはかなり大きいと思います。おそらく私のアプリはメモリ リークです。しかし、私は初心者であり、それを解決する方法がわかりません。私のコードに問題があり、メモリリークが発生するのを手伝ってもらえますか? どうもありがとうございました!

XAML:

<TextBlock TextWrapping="Wrap"
           FontSize="11"
           Padding="5,3,3,3">
        <Run x:Name="a_time"
             Foreground="Blue" />
        <Run x:Name="a_now"
             FontStyle="Italic" />
        <Run x:Name="a_id" />
        <LineBreak />        
        <Run x:Name="a_name"
             Foreground="Blue" />
        <Run x:Name="a_title"
             Foreground="Red"
             Tag=""
             MouseUp="a_MouseUp"
             Cursor="Hand" />
        <LineBreak />        
        <Run x:Name="a_content"
             Foreground="Gray" />
</TextBlock>

コード:

    List<Alert> alert_list = new List<Alert>();

    void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (alert_list.Count == 0) return;
        this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
        {
            this.Background = (this.Background == Brushes.Yellow) ? Brushes.LemonChiffon : Brushes.Yellow;
            Point m = Mouse.GetPosition(this);
            if ((m.X > 0 & m.X < Width & m.Y > 0 & m.Y < Height) | Keyboard.IsKeyDown(Key.LeftCtrl) | Keyboard.IsKeyDown(Key.RightCtrl)) { showemail_tick = 1; return; }

            Alert al = alert_list[alert_list.Count - 1];
            a_title.Tag = al.e_link;
            a_time.Text = al.e_time + "    ";
            a_now.Text = DateTime.Now.ToString("dd/MM/yy HH:mm");
            a_id.Text = al.e_id;
            a_name.Text = al.e_name + "  ";
            a_title.Text = al.e_title;
            a_content.Text = al.e_content;

            alert_list.RemoveAt(alert_list.Count - 1);
        }));
    }


public class Alert
{
    public string e_time = "";
    public string e_id = "";
    public string e_link = "";
    public string e_name = "";
    public string e_title = "";
    public string e_content = "";
    public bool e_bip = true;
}
4

1 に答える 1