【问题标题】:System.OutOfMemoryException while sending a lot of messages with attachments using MailKit使用 MailKit 发送大量带有附件的消息时出现 System.OutOfMemoryException
【发布时间】:2017-07-12 22:25:25
【问题描述】:

我正在使用 MailKit 发送大量带有大附件 (20 MB - 50 MB) 的邮件。当我的应用程序长时间工作(约 4 小时)并发送这些消息时,RAM 使用量正在增长,并且在某一时刻程序意外关闭而没有任何错误消息。一些用户从他的日志中向我发送了信息(有趣的是为什么他的计算机程序没有关闭?):

System.OutOfMemoryException: Zgłoszono wyjątek typu 'System.OutOfMemoryException'。 w MimeKit.IO.MemoryBlockStream.Write(Byte[] 缓冲区,Int32 偏移量,Int32 计数)w MimeKit.AttachmentCollection.LoadContent(MimePart 附件, 流流)w MimeKit.AttachmentCollection.CreateAttachment(ContentType contentType, 字符串文件名,流流)w MimeKit.AttachmentCollection.Add(字符串文件名) w MailExchange.Form1.makeSend(String nazwa) w c:\Users\DamianOS.MP5\Documents\mailexchange\MailExchange\Form1.cs:行 587

这里是源文件(行匹配):https://bitbucket.org/DamianOS_MP5/mailexchange/src/117df6fef0628e13c5ded35e234e06f3852b95f3/MailExchange/Form1.cs?at=master&fileviewer=file-view-default

我知道那是我的错。我在这里问了一个类似的问题:System.OutOfMemoryException while downloading a lot of attachments with MailKit,问题已经解决。但这里的情况有点不同。

我将非常感谢您的建议。

来自 JetBrains dotMemory 的屏幕:

【问题讨论】:

    标签: out-of-memory attachment mailkit


    【解决方案1】:

    您的内存不足,因为您正在向程序中的列表添加东西,这些东西只会不断增长和增长。

    不要那样做。

    【讨论】:

    • 好的,但是哪个列表? builder = null; zalacznik = null; message = null; 每次发送消息后都没有结果:(
    • 您的列表仍在增长,即使它们的所有元素都设置为 null。
    • 仅仅因为你在 makeSend() 方法中得到 OutOfMemoryException 并不意味着这就是泄漏的地方。您的代码中有大量其他列表永远不会被清理。
    • 一周后我发现了一个错误。现在它工作正常:)
    猜你喜欢
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 2020-11-20
    • 2015-08-28
    • 1970-01-01
    • 2021-08-31
    • 2018-12-07
    相关资源
    最近更新 更多