私は約180,000レコードのデータベースを持っています。私はこれらのレコードのそれぞれにpdfファイルを添付しようとしています。各pdfのサイズは約250kbです。しかし、約1分後に私のプログラムは約1 GBのメモリを使い始め、私はそれをやめなければなりません。私はそれをやってみましたので、各linqオブジェクトへの参照は一度更新されても削除されますが、それは役に立たないようです。参照をクリアするにはどうすればよいですか?あなたの助けlinqサブチェンジのメモリが不足しています
Private Sub uploadPDFs(ByVal args() As String)
Dim indexFiles = (From indexFile In dataContext.IndexFiles
Where indexFile.PDFContent = Nothing
Order By indexFile.PDFFolder).ToList
Dim currentDirectory As IO.DirectoryInfo
Dim currentFile As IO.FileInfo
Dim tempIndexFile As IndexFile
While indexFiles.Count > 0
tempIndexFile = indexFiles(0)
indexFiles = indexFiles.Skip(1).ToList
currentDirectory = 'I set the directory that I need
currentFile = 'I get the file that I need
writePDF(currentDirectory, currentFile, tempIndexFile)
End While
End Sub
Private Sub writePDF(ByVal directory As IO.DirectoryInfo, ByVal file As IO.FileInfo, ByVal indexFile As IndexFile)
Dim bytes() As Byte
bytes = getFileStream(file)
indexFile.PDFContent = bytes
dataContext.SubmitChanges()
counter += 1
If counter Mod 10 = 0 Then Console.WriteLine(" saved file " & file.Name & " at " & directory.Name)
End Sub
Private Function getFileStream(ByVal fileInfo As IO.FileInfo) As Byte()
Dim fileStream = fileInfo.OpenRead()
Dim bytesLength As Long = fileStream.Length
Dim bytes(bytesLength) As Byte
fileStream.Read(bytes, 0, bytesLength)
fileStream.Close()
Return bytes
End Function
私はこの方法をとっていましたが、しばしばプログラムを遅くする初期クエリを実行していました。私はそれを行うより適切な方法があることを望んでいた。 – Leon
非常に助けていただきありがとうございますbtw – Leon
@レーオン:わずか18万レコードで、検索は驚異的に速くなるはずです。そうでない場合は、索引付け(特にPDFFolder'を参照)を調べることをお勧めします。たぶん10レコードから100レコードに上がります...基本的には適切なバランスを見つけようとします。 –