我写了这个从视频文件中获取exif数据的类,代码运行正常,但如果我循环浏览大量的视频文件,我的内存不足。
它似乎没有释放对shell文件的引用,我试图将它设置为null而没有运气
如何释放内存?感谢
class Program
{
static void Main(string[] args)
{
List<vFile> VideoFileList = new List<vFile>();
foreach (string filepath in Directory.GetFiles(@"D:\VIDEO", "*.*", SearchOption.AllDirectories))
VideoFileList.Add(new vFile(filepath));
Console.WriteLine("Ended");
Console.ReadKey();//Prevent Close
}
}
class vFile
{
//File
public string FileName { get; set; }
public string FileType { get; set; }
public string FilePath { get; set; }
public double FileSize { get; set; }
public DateTime MediaCreated { get; set; }
//Shell
public string[] Artist { get; set; }
public string[] Keywords { get; set; }
public ulong Duration { get; set; }
public int FrameHeight { get; set; }
public int FrameWidth { get; set; }
public int Rating { get; set; }
public string Publisher { get; set; }
public vFile(string filepath)
{
//File
FileName = Path.GetFileNameWithoutExtension(filepath);
FileType = Path.GetExtension(filepath).Replace(".", "");
FilePath = Path.GetFullPath(filepath);
FileSize = new System.IO.FileInfo(filepath).Length;
MediaCreated = File.GetCreationTime(filepath);
//Shell
using (ShellFile shellFile = ShellFile.FromFilePath(filepath))
{
if (shellFile.Properties.System.Music.Artist.Value != null)
Artist = shellFile.Properties.System.Music.Artist.Value;
if (shellFile.Properties.System.Keywords.Value != null)
Keywords = shellFile.Properties.System.Keywords.Value;
if (shellFile.Properties.System.Media.Duration.Value != null)
Duration = shellFile.Properties.System.Media.Duration.Value.Value;
if (shellFile.Properties.System.Video.FrameHeight.Value != null)
FrameHeight = Int32.Parse(shellFile.Properties.System.Video.FrameHeight.Value.Value.ToString());
if (shellFile.Properties.System.Video.FrameWidth.Value != null)
FrameWidth = Int32.Parse(shellFile.Properties.System.Video.FrameWidth.Value.Value.ToString());
if (shellFile.Properties.System.Rating.Value != null)
Rating = Int32.Parse(shellFile.Properties.System.Rating.Value.Value.ToString());
if (shellFile.Properties.System.Media.Publisher.Value != null)
Publisher = shellFile.Properties.System.Media.Publisher.Value;
}
}
}