【发布时间】:2013-06-06 03:12:43
【问题描述】:
我正在使用最新版本的 Automapper (v3.0.0.0-ci1036),当它使用二进制数据转换对象时,它使用了大量的内存。 (10MB 文件为 200MB)。这是一个正在转换的“文件”示例:
class Program
{
static void Main(string[] args)
{
convertObject();
}
private static void convertObject()
{
var rnd = new Random();
var fileContents = new Byte[1024 * 1024 * 10];
rnd.NextBytes(fileContents);
var attachment = new Attachment { Content = fileContents };
Mapper.CreateMap<Attachment, AttachmentDTO>();
Console.WriteLine("Press enter to convert");
Console.ReadLine();
var dto = Mapper.Map<Attachment, AttachmentDTO>(attachment);
Console.WriteLine(dto.Content.Length + " bytes");
Console.ReadLine();
}
}
public class Attachment
{
public byte[] Content { get; set; }
}
public class AttachmentDTO
{
public byte[] Content { get; set; }
}
我的代码有问题吗,还是我必须停止对包含二进制数据的对象使用自动映射器?
【问题讨论】:
-
映射后是否会飙升然后恢复正常?
-
不,它会一直保持这种状态,直到应用程序被杀死
-
一个原因可能是您使用字节数组:字节数组要求内存中的所有字节都是连续的。
标签: memory-leaks automapper .net-4.5